如何更改php文件以上传图片而不是字符串?

时间:2019-01-10 01:25:05

标签: php android mysql

我正在使用android应用程序将图像上传到服务器,我想将我的php文件从将图像作为字符串上传到多部分更改。

我想更改,因为我有一个问题,我无法通过我的android应用程序在服务器上上传超过700KB的图像,我尝试了所有操作,但仍然存在相同的问题,有人建议我更改为多部分内容,因为更好的功能。

那么,您能帮我更改此文件以适合多部分吗?

<?php 
include "connection.php.php";

$sucess = 105;
$fail = 107;

$images = $_POST['sales_images']; //images list[]
$image_name = $_POST['sales_images_names']; //images_names list[]


$bedroom = $_POST['bedroom'];
$bathroom = $_POST['bathroom'];
$size = $_POST['size'];

$ref = $_POST['ref'];

$hotDeal = $_POST['hotDeal'];

$sql = "INSERT INTO `sale`(`ref`, `sqm`, `avaliable`, `bedroom`, `bathroom`, `hot_deal`) VALUES ('$ref','$size',1,'$bedroom','$bathroom',$hotDeal)";
$result = mysqli_query($con, $sql);

if ($result === TRUE) {
    $last_id = $con->insert_id;

    $length = count($images);

    for($i = 0; $i < $length; $i++) {
        $imageNow = time();
        $new_imageFilename = $imageNow . "_" . $image_name[$i];

        $sql6 = "INSERT INTO `sale_image`(`sale_id`, `img_url`) VALUES ('$last_id','$new_imageFilename')";
        $result6 = mysqli_query($con, $sql6);

        $binary=base64_decode($images[$i]);
        $file = fopen('files/sales/' . $new_imageFilename, 'wb');
        fwrite($file, $binary);
        fclose($file);      
    }

    echo "New record created successfully. Last inserted ID is: " . $last_id;
} else {
    echo "Error: " . $sql . "<br>" . $con->error;
}

$jsonResult = '{"state":';
if($result){
    $jsonResult.= $sucess;
}else {
    $jsonResult.= $fail;
}
$jsonResult .="}";
print_r($jsonResult);
?>

0 个答案:

没有答案