Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php tweetImage未显示图像_Php_Mysql_Sql_Regex - Fatal编程技术网

Php tweetImage未显示图像

Php tweetImage未显示图像,php,mysql,sql,regex,Php,Mysql,Sql,Regex,这是我的51号线 <img src="'.BASE_URL.$tweet->tweetImage.'"/> tweetImage.“/> 这是我的密码 <?php class Tweet extends User { function _construct($pdo) { $this->pdo = $pdo; } public function tweets($user_id)

这是我的51号线

<img src="'.BASE_URL.$tweet->tweetImage.'"/>
tweetImage.“/>
这是我的密码

<?php
class Tweet extends User
{
    
    function _construct($pdo)
    {
        $this->pdo = $pdo;
    }
    public function tweets($user_id)
    {
        $stmt = $this->pdo->prepare("SELECT * FROM `tweets` LEFT JOIN `users` ON `tweetBy` = `user_id` WHERE `tweetBy` = :user_id AND `retweetID` = '0' OR `tweetBy` = `user_id` AND `retweetBy` != :user_id");
        $stmt->bindParam(":user_id", $user_id, PDO::PARAM_INT);
        $stmt->execute();
        $tweets = $stmt->fetchAll(PDO::FETCH_OBJ);
        
        foreach($tweets as $tweet)
        {
            $likes = $this->likes($user_id, $tweet->tweetID); 
            $retweet = $this->checkRetweet($tweet->tweetID, $user_id);
            $user = $this->userData($tweet->retweetBy);
            echo '<div class="all-tweet">
<div class="t-show-wrap">   
 <div class="t-show-inner">
 '.((!empty($tweet->retweetMsg) && $tweet->tweetID === $retweet['tweetID'] or $tweet->retweetID > 0) ? '  
    <div class="t-show-banner">
        <div class="t-show-banner-inner">
            <span><i class="fa fa-retweet" aria-hidden="true"></i></span><span>'.$user->screenName.' Retweeted</span>
        </div>
    </div>' 
    : '').'
    '.((!empty($tweet->retweetMsg) && $tweet->tweetID === $retweet['tweetID'] OR $tweet->retweetID > 0) ? '<div class="t-show-head">
                      <div class="t-show-img">
                            <img src="'.BASE_URL.$user->profileImage.'"/>
                        </div>
                <div class="t-s-head-content">
                    <div class="t-h-c-name">
                        <span><a href="'.BASE_URL.$user->username.'">'.$user->screenName.'</a></span>
                        <span>@'.$user->username.'</span>
                        <span>'.$retweet['postedOn'].'</span>
                    </div>
                    <div class="t-h-c-dis">
                        '.$this->getTweetLinks($tweet->retweetMsg).'
                    </div>
                </div>
            </div>
            <div class="t-s-b-inner">
                <div class="t-s-b-inner-in">
                    <div class="retweet-t-s-b-inner">
                    '.((!empty($tweet->tweetImage)) ? '
                        <div class="retweet-t-s-b-inner-left">
                            <img src="'.BASE_URL.$tweet->tweetImage.'"/>    
                        </div>' : '').'
                        <div class="retweet-t-s-b-inner-right">
                            <div class="t-h-c-name">
                                <span><a href="'.BASE_URL.$tweet->username.'">'.$tweet->screenName.'</a></span>
                                <span>@'.$tweet->username.'</span>
                                <span>'.$tweet->postedOn.'</span>
                            </div>
                            <div class="retweet-t-s-b-inner-right-text">        
                                '.$tweet->status.'
                            </div>
                        </div>
                    </div>
                </div>
            </div>' : '
    <div class="t-show-popup">
        <div class="t-show-head">
            <div class="t-show-img">
                <img src="'.$tweet->profileImage.'"/>
            </div>
            <div class="t-s-head-content">
                <div class="t-h-c-name">
                    <span><a href="'.$tweet->username.'">'.$tweet->screenName.'</a></span>
                    <span>@'.$tweet->username.'</span>
                    <span>'.$tweet->postedOn.'</span>
                </div>
                <div class="t-h-c-dis">
                    '.$this->getTweetLinks($tweet->status).'
                </div>
            </div>
        </div>'.
        ((!empty($tweet->tweetImage)) ? 
         '<!--tweet show head end-->
        <div class="t-show-body">
          <div class="t-s-b-inner">
           <div class="t-s-b-inner-in">
             <img src="'.$tweet->tweetImage.'" class="imagePopup"/>
           </div>
          </div>
        </div>
        <!--tweet show body end-->
        ' : '').'
        
     </div>').'
    <div class="t-show-footer">
        <div class="t-s-f-right">
            <ul> 
                <li><button><i class="fa fa-share" aria-hidden="true"></i></button></li>    
                <li>'.((isset($retweet['retweetID']) ? $retweet['retweetID'] === $tweet->tweetID : '') ? 
                '<button class="retweeted" data-tweet="'.$tweet->tweetID.'" data-user="'.$tweet->tweetBy.'"><i class="fa fa-retweet" aria-hidden="true"></i><span class = "retweetsCount">'.$tweet->retweetCount.'</span></button>' : 
                '<button class="retweet" data-tweet="'.$tweet->tweetID.'" data-user="'.$tweet->tweetBy.'"><i class="fa fa-retweet" aria-hidden="true"></i><span class = "retweetsCount">'.(($tweet->retweetCount > 0) ? $tweet->retweetCount : '').'</span></button>').'
                </li>
                <li>'.((isset($likes['likeOn']) ? $likes['likeOn'] === $tweet->tweetID : '') ? 
                                    '<button class="unlike-btn" data-tweet="'.$tweet->tweetID.'" data-user="'.$tweet->tweetBy.'"><i class="fa fa-heart" aria-hidden="true"></i><span class="likesCounter">'.(($tweet->likesCount > 0) ? $tweet->likesCount : '' ).'</span></button>' : 
                                    '<button class="like-btn" data-tweet="'.$tweet->tweetID.'" data-user="'.$tweet->tweetBy.'"><i class="fa fa-heart-o" aria-hidden="true"></i><span class="likesCounter">'.(($tweet->likesCount > 0) ? $tweet->likesCount : '' ).'</span></button>').'
                                </li>                   
                    <li>
                    <a href="#" class="more"><i class="fa fa-ellipsis-h" aria-hidden="true"></i></a>
                    <ul> 
                      <li><label class="deleteTweet">Delete Tweet</label></li>
                    </ul>
                </li>
            </ul>
        </div>
    </div>
</div>
</div>
</div>';
        }
    } 
    public function getTrendByHash($hashtag){
        $stmt = $this->pdo->prepare("SELECT * FROM `trends` WHERE `hashtag` LIKE :hashtag LIMIT 5");
        $stmt->bindValue(":hashtag", $hashtag.'%');
        $stmt->execute();
        return $stmt->fetchAll(PDO::FETCH_OBJ);
    }
    
    public function getMention($mention)
    {
        $stmt = $this->pdo->prepare("SELECT `user_id`,`username`,`screenName`,`profileImage` FROM `users` WHERE `username` LIKE :mention OR `screenName` LIKE :mention LIMIT 5");
        $stmt->bindValue(':mention', $mention.'%');
        $stmt->execute();
        return $stmt->fetchAll(PDO::FETCH_OBJ);
    }
    
    public function addTrend($hashtag)
    {
        preg_match_all("/#+([a-zA-Z0-9_]+)/i", $hashtag, $matches);
        if($matches)
        {
            $result = array_values($matches[1]);
        }
        $sql = "INSERT INTO `trends` (`hashtag`, `createdOn`) VALUES (:hashtag, CURRENT_TIMESTAMP)";
        foreach ($result as $trend) {
            if($stmt = $this->pdo->prepare($sql)){
                $stmt->execute(array(':hashtag' => $trend));
            }
        }
    }
    public function getTweetLinks($tweet)
    {
        $tweet = preg_replace("/(https?:\/\/)([\w]+.)([\w\.]+)/", "<a href='$0' target='_blank'>$0</a>", $tweet);
        $tweet = preg_replace("/#([\w]+)/", "<a href='http://localhost/twitter/hashtag/$1'>$0</a>", $tweet);
        $tweet = preg_replace("/@([\w]+)/", "<a href='http://localhost/twitter/$1'>$0</a>", $tweet);
        return $tweet;
    }
    
    public function getPopupTweet($tweet_id){
        $stmt = $this->pdo->prepare("SELECT * FROM `tweets`,`users` WHERE `tweetID` = :tweet_id AND `tweetBy` = `user_id`");
        $stmt->bindParam(":tweet_id", $tweet_id, PDO::PARAM_INT);
        $stmt->execute();
        return $stmt->fetch(PDO::FETCH_OBJ);
    }
    
    public function retweet($tweet_id, $user_id, $get_id, $comment)
    {
        $stmt = $this->pdo->prepare("UPDATE `tweets` SET `retweetCount` = `retweetCount`+1 WHERE `tweetID` = :tweet_id AND `tweetBy` = :get_id");
        $stmt->bindParam(":tweet_id", $tweet_id, PDO::PARAM_INT);
        $stmt->bindParam(":get_id", $get_id, PDO::PARAM_INT);
        $stmt->execute();
        
        $stmt = $this->pdo->prepare("INSERT INTO `tweets` (`status`,`tweetBy`,`retweetID`,`retweetBy`,`tweetImage`,`postedOn`,`likesCount`,`retweetCount`,`retweetMsg`) SELECT `status`,`tweetBy`,`tweetID`,:user_id,CURRENT_TIMESTAMP`tweetImage`,`postedOn`,`likesCount`,`retweetCount`,:retweetMsg FROM `tweets` WHERE `tweetID` = :tweet_id");
        $stmt->bindParam(":user_id", $user_id, PDO::PARAM_INT);
        $stmt->bindParam(":retweetMsg", $comment, PDO::PARAM_STR);
        $stmt->bindParam(":tweet_id", $tweet_id, PDO::PARAM_INT);
        $stmt->execute();
    }
    
    public function checkRetweet($tweet_id, $user_id){
        $stmt = $this->pdo->prepare("SELECT * FROM `tweets` WHERE `retweetID` = :tweet_id AND `retweetBy` = :user_id OR `tweetID` = :tweet_id and `retweetBy` = :user_id");
        $stmt->bindParam(":tweet_id", $tweet_id, PDO::PARAM_INT);
        $stmt->bindParam(":user_id", $user_id, PDO::PARAM_INT);
        $stmt->execute();
        return $stmt->fetch(PDO::FETCH_ASSOC);
    }
    
    public function addLike($user_id, $tweet_id, $get_id)
    {
        $stmt = $this->pdo->prepare("UPDATE `tweets` SET `likesCount` = `likesCount` +1 WHERE `tweetID` = :tweet_id");
        $stmt->bindParam(":tweet_id", $tweet_id, PDO::PARAM_INT);
        $stmt->execute();
        
        $this->create('likes', array('likeBy' => $user_id, 'likeOn' => $tweet_id));
    }
    
        public function unlike($user_id, $tweet_id, $get_id)
    {
        $stmt = $this->pdo->prepare("UPDATE `tweets` SET `likesCount` = `likesCount` -1 WHERE `tweetID` = :tweet_id");
        $stmt->bindParam(":tweet_id", $tweet_id, PDO::PARAM_INT);
        $stmt->execute();
        
        $this->create('likes', array('likeBy' => $user_id, 'likeOn' => $tweet_id));
    }
    
    public function likes($user_id, $tweet_id){
        $stmt = $this->pdo->prepare("SELECT * FROM `likes` WHERE `likeBy` = :user_id AND `likeOn` = :tweet_id");
        $stmt->bindParam(":user_id", $user_id, PDO::PARAM_INT);
        $stmt->bindParam(":tweet_id", $tweet_id, PDO::PARAM_INT);
        $stmt->execute();
        return $stmt->fetch(PDO::FETCH_ASSOC);
    } 
}
?><br><br>

在db表中,tweets.tweetImage列是日期时间。 除最后一行为时间戳外,所有行均为空


将其更改为文件路径或uri,之后应该可以使用。

那么,这创建的实际HTML是什么样子的?图像的
src
属性中是否有正确的URL,或者是否有错误消息将其输入到输出中?(您是否启用了正确的PHP错误报告功能?如果没有,请立即开始执行!)浏览器控制台会说什么,它是否显示图像URL请求的404?这就是我的错误报告的设置方式。
error\u reporting=E\u ALL&~E\u DEPRECATED&~E\u STRICT
我需要更改什么吗?.home.php输出中的所有其他内容都正常工作我只是没有得到
tweetImage
好的,这回答了其中一个问题问题。错误
“注意:尝试访问C:\xampp\htdocs\twitter\core\classes\tweet.php中bool类型值的数组偏移量…”
可能与我的“tweetImage”错误无关。
<?php
    include 'core/init.php';
    $user_id = $_SESSION['user_id'];
    $user = $getFromU->userData($user_id);
    if($getFromU->loggedIn() === false)
    {
        header('Location: index.php');
    }
    
    if(isset($_POST['tweet']))
    {
        $status = $getFromU->checkinput($_POST['status']);
        $tweetImage = '';
        
        if(!empty($status) or !empty($_FILES['file']['name'][0]))
        {
            if(!empty($_FILES['file']['name'][0]))
            {
                $tweetImage = $getFromU->uploadImage($_FILES['file']);
            }
            
            if(strlen($status) > 140)
            {
                $error = "The text of your tweet is too long!";
            }
            $getFromU->create('tweets' ,array('status' => $status, 'tweetBy' => $user_id, 'tweetImage' => $tweetImage, 'postedOn' => date('Y-m-d H:i:s')));
            preg_match_all("/#+([a-zA-Z0-9_]+)/i", $status, $hashtag);
            
            if(!empty($hashtag))
            {
                $getFromT->addTrend($status);
            }
        }
        else
        {
            $error = "Try adding an image/text then click tweet!!";
        }
    }
?>

<!DOCTYPE HTML> 
 <html>
    <head>
        <title>Tweety</title>
          <meta charset="UTF-8" />
          <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.css"/>  
          <link rel="stylesheet" href="assets/css/style-complete.css"/> 
          <script src="https://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>     
    </head>
    <!--Helvetica Neue-->
<body>
<div class="wrapper">
<!-- header wrapper -->
<div class="header-wrapper">

<div class="nav-container">
    <!-- Nav -->
    <div class="nav">
        
        <div class="nav-left">
            <ul>
                <li><a href="#"><i class="fa fa-home" aria-hidden="true"></i>Home</a></li>
                <li><a href="i/notifications"><i class="fa fa-bell" aria-hidden="true"></i>Notification</a></li>
                <li><i class="fa fa-envelope" aria-hidden="true"></i>Messages</li>
            </ul>
        </div><!-- nav left ends-->

        <div class="nav-right">
            <ul>
                <li>
                    <input type="text" placeholder="Search" class="search"/>
                    <i class="fa fa-search" aria-hidden="true"></i>
                    <div class="search-result">         
                    </div>
                </li>

                <li class="hover"><label class="drop-label" for="drop-wrap1"><img src="<?php echo $user->profileImage;?>"/></label>
                <input type="checkbox" id="drop-wrap1">
                <div class="drop-wrap">
                    <div class="drop-inner">
                        <ul>
                            <li><?php echo $user->username;?></a></li>
                            <li><a href="settings/account">Settings</a></li>
                            <li><a href="includes/logout.php">Log out</a></li>
                        </ul>
                    </div>
                </div>
                </li>
                <li><label class="addTweetBtn">Tweet</label></li>
            </ul>
        </div><!-- nav right ends-->

    </div><!-- nav ends -->

</div><!-- nav container ends -->

</div><!-- header wrapper end -->

<script type="text/javascript" src = "assets/js/search.js"></script>
<script type="text/javascript" src = "assets/js/hashtag.js"></script>

<!---Inner wrapper-->
<div class="inner-wrapper">
<div class="in-wrapper">
    <div class="in-full-wrap">
        <div class="in-left">
            <div class="in-left-wrap">
        <div class="info-box">
            <div class="info-inner">
                <div class="info-in-head">
                    <!-- PROFILE-COVER-IMAGE -->
                    <img src="<?php echo $user->profileCover;?>"/>
                </div><!-- info in head end -->
                <div class="info-in-body">
                    <div class="in-b-box">
                        <div class="in-b-img">
                        <!-- PROFILE-IMAGE -->
                            <img src="<?php echo $user->profileImage;?>"/>
                        </div>
                    </div><!--  in b box end-->
                    <div class="info-body-name">
                        <div class="in-b-name">
                            <div><a href="<?php echo $user->username;?>"><?php echo $user->screenName;?></a></div>
                            <span><small><a href="<?php echo $user->username;?>"><?php echo $user->username;?></a></small></span>
                        </div><!-- in b name end-->
                    </div><!-- info body name end-->
                </div><!-- info in body end-->
                <div class="info-in-footer">
                    <div class="number-wrapper">
                        <div class="num-box">
                            <div class="num-head">
                                TWEETS
                            </div>
                            <div class="num-body">
                                10
                            </div>
                        </div>
                        <div class="num-box">
                            <div class="num-head">
                                FOLLOWING
                            </div>
                            <div class="num-body">
                                <span class="count-following"><?php echo $user->following;?></span>
                            </div>
                        </div>
                        <div class="num-box">
                            <div class="num-head">
                                FOLLOWERS
                            </div>
                            <div class="num-body">
                                <span class="count-followers"><?php echo $user->followers;?></span>
                            </div>
                        </div>  
                    </div><!-- mumber wrapper-->
                </div><!-- info in footer -->
            </div><!-- info inner end -->
        </div><!-- info box end-->

    <!--==TRENDS==-->
      <!---TRENDS HERE-->
    <!--==TRENDS==-->

    </div><!-- in left wrap-->
        </div><!-- in left end-->
        <div class="in-center">
            <div class="in-center-wrap">
                <!--TWEET WRAPPER-->
                <div class="tweet-wrap">
                    <div class="tweet-inner">
                         <div class="tweet-h-left">
                            <div class="tweet-h-img">
                            <!-- PROFILE-IMAGE -->
                                <img src="<?php echo $user->profileImage;?>"/>
                            </div>
                         </div>
                         <div class="tweet-body">
                         <form method="post" enctype="multipart/form-data">
                            <textarea class="status" name="status" placeholder="Type Something here!" rows="4" cols="50"></textarea>
                            <div class="hash-box">
                                <ul>
                                </ul>
                            </div>
                         </div>
                         <div class="tweet-footer">
                            <div class="t-fo-left">
                                <ul>
                                    <input type="file" name="file" id="file"/>
                                    <li><label for="file"><i class="fa fa-camera" aria-hidden="true"></i></label>
                                    <span class="tweet-error"><?php if(isset($error)){echo $error;}else if(isset($imageError)){echo $imageError;}?></span>
                                    </li>
                                </ul>
                            </div>
                            <div class="t-fo-right">
                                <span id="count">140</span>
                                <input type="submit" name="tweet" value="tweet"/>
                        </form>
                            </div>
                         </div>
                    </div>
                </div><!--TWEET WRAP END-->

            
                <!--Tweet SHOW WRAPPER-->
                 <div class="tweets">
                    <?php $getFromT->tweets($user_id);?>
                 </div>
                <!--TWEETS SHOW WRAPPER-->

                <div class="loading-div">
                    <img id="loader" src="assets/images/loading.svg" style="display: none;"/> 
                </div>
                <div class="popupTweet"></div>
                <!--Tweet END WRAPER-->
            <script type="text/javascript" src = "assets/js/like.js"></script>
            <script type="text/javascript" src = "assets/js/retweet.js"></script>
            </div><!-- in left wrap-->
        </div><!-- in center end -->

        <div class="in-right">
            <div class="in-right-wrap">

            <!--Who To Follow-->
              <!--WHO_TO_FOLLOW HERE-->
            <!--Who To Follow-->

            </div><!-- in left wrap-->

        </div><!-- in right end -->

    </div><!--in full wrap end-->

</div><!-- in wrappper ends-->
</div><!-- inner wrapper ends-->
</div><!-- ends wrapper -->
</body>

</html>