0

我正在上传并请求 id 以在上传后检索图像。但是,在我检索之前,我什至可以将它插入到我的 MySQL 数据库中;

顺便说一句,问题出在第 19 行,即

"$query = "INSERT INTO profilepicture (`id`,`name`,`image`) VALUES ('','".$image_name."','".$image."')";"

这是我使用的代码

<?php
 $con = mysqli_connect('127.0.0.1', 'root', '', 'test');
$files = $_FILES['uploadProfilePicture']['tmp_name'];

 if(!isset($files)){
echo("wrong file");
 }else
 {
$image = file_get_contents($_FILES['uploadProfilePicture']['tmp_name']);
$image_name = $_FILES['uploadProfilePicture']['name'];
$image_size = getimagesize($_FILES['uploadProfilePicture']['tmp_name']);

if($image_size == false) 
{
    echo("Thats is not an image");
}else
{
    $query = "INSERT INTO profilepicture (`id`,`name`,`image`) VALUES ('','".$image_name."','".$image."')";
    if(!$insert = mysqli_query($con, $query))
    {
    echo("problem uploading");  
    }else
    {

        $lastid = mysql_insert_id();
        echo "image uploaded.</p> Your Image</p> <img src=getImage.php?id=".$lastid.">";
    }
}
 }
 ?>



<div class="loginCheck">
        <div class="profilePicture">
            <form action="ProfileImages/FileUpload.php" method="POST" enctype="multipart/form-data">
                <input  type="file" name="uploadProfilePicture"/> <input type="submit" value="Upload" />
            </form>



        </div>
    </div>
4

2 回答 2

0

我敢打赌,您对这条线有疑问:

$image = file_get_contents($_FILES['uploadProfilePicture']['tmp_name']);

试试这个:

$image = mysql_real_escape_string(file_get_contents($_FILES['uploadProfilePicture']['tmp_name']));

您需要转义该字符串。它可能有一个报价。您应该考虑使用准备好的语句

于 2013-04-09T22:04:03.157 回答
0

这个字符串应该如何构造?

"$query = "INSERT INTO profilepicture (`id`,`name`,`image`) VALUES ('','".$image_name."','".$image."')";"

如上?或者:

$query = "INSERT INTO profilepicture (`id`,`name`,`image`) VALUES ('','".$image_name."','".$image."')";

$注意到在和之前删除了引号;吗?

于 2015-01-13T22:34:35.037 回答