Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.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 如何显示数据库中的图像';s表';存储它的路径是什么?_Php_Sql - Fatal编程技术网

Php 如何显示数据库中的图像';s表';存储它的路径是什么?

Php 如何显示数据库中的图像';s表';存储它的路径是什么?,php,sql,Php,Sql,我正在使用会话从数据库表接收信息。。。但我不太确定如何获得图像,因为如果我这么说 echo '$_SESSION[pic_location]'; 我不知道是否有人能以某种方式使用img标签 它给了我一个图像路径的字符串,而不是图像本身。我怎样才能解决这件事 这是我的picUpload.php文档 <?php include 'connect.php'; include 'header.php'; if(iss

我正在使用会话从数据库表接收信息。。。但我不太确定如何获得图像,因为如果我这么说

echo '$_SESSION[pic_location]';
我不知道是否有人能以某种方式使用img标签

它给了我一个图像路径的字符串,而不是图像本身。我怎样才能解决这件事

这是我的picUpload.php文档

<?php
             include 'connect.php';
             include 'header.php';

             if(isset($_SESSION['signed_in']) && $_SESSION['signed_in'] == true)
            {
                 //This is the directory where images will be saved 
                 $target=$_SERVER['DOCUMENT_ROOT'] . "/avatars/" . basename( $_FILES['file']['name']); 

                 //$target = "avatars/"; 
                //$target = $target . basename( $_FILES['file']['name']); 

                 //This gets all the other information from the form 
                 $pic_location=($_FILES['file']['name']); 

                 //Writes the information to the database
                 $sql = "UPDATE users SET pic_location='$target' WHERE user_id=" . $_SESSION['user_id'];
                 $result = mysql_query($sql);

                 if(!$result)
                {
                    //something went wrong, display the error
                    echo "Sorry, there was a problem uploading your file.";
                    //echo mysql_error(); //debugging purposes, uncomment when needed
                }
                else
                {
                    //Writes the photo to the server 
                    if(move_uploaded_file($_FILES['file']['tmp_name'], $target))
                    {
                        //Tells you if its all ok 
                        echo "The file ". basename( $_FILES['file']['name']). " has been uploaded, and your information has been added to the directory"; 
                    } 
                    else
                    {
                    //nothing
                    }
                }
            }
?> 

和我想显示图像的my profile.php

<?php
        include 'connect.php';
        include 'header.php';

            //

            if(isset($_SESSION['signed_in']) == false || isset($_SESSION['user_level']) != 1 )
                {
                    //the user is not an admin
                    echo '<br/>';
                    echo 'Sorry! You have to be <a href="/signin.php"><b>logged in</b></a> to view your profile <a href="signup.php" title="Become a registered user!"></a>.';
                    echo '<br/><br/>';
                }
                else
                {
                    echo '<h2>Profile of </h2>'.$_SESSION['user_name'];
                    echo '<h2>Info about you: </h2>';

                    //user_pass = '" . mysql_real_escape_string($_POST['user_pass']) . "'";

                    $explodedPath = explode("C:/xampp/htdocs/avatars" , $_SESSION['pic_location']);
                    echo '<img src="http://[localhost]'.$explodedPath[1].'" />';

                    echo '<br/><br/>';
                    echo '<b>Logged in as: </b>'.$_SESSION['user_name'];    echo'<pp><a href="#" title="Change your user name">edit</a></pp>';
                    echo '<br/><br/>';
                    echo '<b>Your email address: </b>'.$_SESSION['user_email']; echo'<pp><a href="#" title="Change your email address">edit</a></pp>';
                    echo '<br/><br/>';
                    echo '<b>Your user level: </b>'.$_SESSION['user_level'].'   (1 = admin AND 0 = user)';
                    echo '<br/><br/>';
                    echo '<b>Your friends: </b> // FRIENDS';

                    //echo 'Welcome, ' . $_SESSION['user_name'] . '! <br /><br/><br/><a href="index.php"><b>Proceed to the link sharing</b></a>.';
                    ///////////////////////////////
                    /// adding users as friends ///
                    ///////////////////////////////

                    //while($user = mysql_fetch_array($result))
                    //echo $user['user_name'].' 
                        //<a href="addfriend.php?user='.$user['id'].'">ADD TO FRIENDS</a><br/>';
                    echo '<br/><br/>';
                    echo '<br/><br/>';
                    echo '<b>Do you want to upload or change your profile picture?</b>';
                    echo '<br/><br/>';
                    echo '<form action="picUpload.php" method="post" enctype="multipart/form-data">
                            <label for="file">Filename: </label>
                            <input type="file" name="file" id="file"/>      
                            <br/><br/>
                            <input type="submit" name="submit" value="Upload" />
                         </form>';

                    //NOW I WANT TO MAKE A SPECIFIC "ADD AS FRIEND" LINK NEXT TO EACH USER


                }
                include 'footer.php';
?>
echo”“;
试试这个

<?php echo '<img src="$_SESSION[pic_location]"; /> ?> 
//Considering $_SESSION[pic_location] giving you the full image path
使用HTML:

<img src="<?php echo $_SESSION['pic_location']; ?>" alt="image" />
“alt=”image“/>

但是要小心XS和错误的路径。

我通过更改

$target=$_SERVER['DOCUMENT_ROOT'] . "/avatars/" . basename( $_FILES['file']['name']);
为此:

$target = "avatars/" . $_FILES['file']['name'];
然后,当我想显示它时,我使用

echo '<img width="50" height="50" src="' . $_SESSION['pic_location'] . '">';
echo';
谢谢你的帮助


Joe:)

好吧,我忘了提到我使用了你的方法,但我只是得到了一个像thingy这样的小圆点字符,而不是图像本身……路径是C:/xampp/htdocs/avatars/beetgejo。jpg@Joemeister:我们无法帮助您了解此信息。没有人知道您的硬盘上是否存在该映像以及“什么”一个像thingy这样的小圆点字符应该是这个意思。你必须通过
explode()
方法打破路径,比如
$explodedPath=explode(“C:/xampp/htdocs”,$\u SESSION[picu location]);
然后追加
[servername]=localhost
如果您在本地机器上进行尝试,我会用两个文件快速更新我的问题:我上传图像的位置(picUpload.php)和我想显示图像的位置(profile.php)。
echo '<img width="50" height="50" src="' . $_SESSION['pic_location'] . '">';