简体   繁体   English

使用 php 时上传图像的大小为 0

[英]Size of uploaded image is 0 while using php

I am trying to upload images to the server, The image is successfully uploaded to both my images folder and SQL database, but the image size is 0. I am using postman to upload the image and in the future, I will use this script to upload images from android.我正在尝试将图像上传到服务器,图像已成功上传到我的图像文件夹和 SQL 数据库,但图像大小为 0。我正在使用 postman 上传图像,将来,我将使用此脚本从 android 上传图像。 Below is my PHP script.下面是我的 PHP 脚本。 Thank You谢谢你

$con = mysqli_connect($host_name, $user_name, $user_pass, $db_name);

$filename = $_FILES['image']['name'];
$productname = $_POST['productname'];
$storename = $_POST['storename'];

$upload_path = "ecomerceimage/$productname.$filename";


$sql = "INSERT INTO `imageinfo` (`id`, `image`, `storename`, `productname`) 
 VALUES (NULL, '$filename', '$storename', '$productname');";
 

 if(mysqli_query($con, $sql)){
    file_put_contents($upload_path, base64_decode($filename));
    echo json_encode(array('response' => "Image uploaded successfylly"));
 }else{
    echo json_encode(array('response' => "Image upload failed"));
 }
 mysqli_close($con);

I am not sure if this would work or not, But I think you're decoding the name only, you should decode the image instead of name.我不确定这是否可行,但我认为您只是在解码名称,您应该解码图像而不是名称。

if(mysqli_query($con, $sql)){
    file_put_contents($upload_path, base64_decode($image));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM