查询将不会插入数据库。 (正确的凭证)

时间:2018-09-07 04:29:49

标签: php mysql

我遇到一个奇怪的问题,未添加将查询值插入数据库的查询。我通过终端使用MySQL,通过这些查询进行查询的文件在我的AWS ubuntu实例上。

这是位于我的AWS实例上的upload.php文件:

Input:1234567.00 or 1234,567.00 or 1234567 should return $1,234,567.00

当我上传图像并且php运行时,我最终收到“文件上传失败,请重试。”打印在我的屏幕上。 -该表名为图像。 任何人都可以识别出可能的问题吗?我以为可能与权限有关,但是凭据正确无误,我无法想象会缺少什么权限。除此之外,我现在迷路了。 谢谢。

(一个简单的演示站点) http://ec2-54-158-61-31.compute-1.amazonaws.com/images/

3 个答案:

答案 0 :(得分:0)

telebot-pianomoves-v1-km   3         4         2            1           9d

答案 1 :(得分:0)

有多种存储图像的方式

如果要将图像存储到数据库中,则需要blob数据类型(列数据类型必须为BLOB) 那么您可以使用以下代码

$imagename=$_FILES["myimage"]["name"]; 

//Get the content of the image and then add slashes to it 
$imagetmp=addslashes (file_get_contents($_FILES['myimage']['tmp_name']));

//Insert the image name and image content in image_table
$insert_image="INSERT INTO image_table VALUES('$imagetmp','$imagename')";

mysql_query($insert_image);

Code reference

如果要将图像添加到目录中并将名称存储到数据库中,则

$uploaddir = '/var/www/uploads/';
    $uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

    echo "<p>";

    if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
      echo "File is valid, and was successfully uploaded.\n";
    } else {
       echo "Upload failed";
    }
//and then execute insert query with image name instead of image

code reference

答案 2 :(得分:0)

您不能以这种方式存储图像内容。 因此,“ $ imgContent = adslashes(file_get_contents($ image));”中存在一些问题。

如果要将图像数据保存到数据库中,则将图像内容转换为base64编码,然后尝试保存编码的数据。