PHP文件上传move_uploaded_file

时间:2019-08-21 11:16:25

标签: php file upload

当我尝试将图像上传到服务器时,Php始终显示错误。 图片:https://ibb.co/r4crqtF

图像大小为120kb,我认为这不是问题。

$product_add_cate = $_POST["product_add_category"];
$target_path = "assets/products/".getImagePath($product_add_cate);
$target_file = $target_path.basename($product_add_imge);
if (move_uploaded_file($_FILES["product_photo"]["tmp_name"], $target_file)) {
    echo "success";
} else {
    echo "error";
}

function getImagePath($img_category) {
    $path = "";
    if ($img_category == "product_antidekubitni_program") {
        $path = "antidekubitni program/";
    } else if ($img_category == "product_bolnicki_kreveti_i_oprema") {
        $path = "bolnicki kreveti i oprema/";
    } else if ($img_category == "product_invalidska_kolica") {
        $path = "invalidska kolica/";
    } else if ($img_category == "product_stake_stapovi") {
        $path = "stake, stapovi i hodalice/";
    } else if ($img_category == "product_toaletni_program") {
        $path = "toaletni program/";
    } else if ($img_category == "product_ortoze_mideri") {
        $path = "ortoze mideri steznici/";
    }
    return $path;
}

图片HTML

<input type="file" name="product_photo" id="fileToUpload" title="Izaberite fotografiju proizvoda" accept="image/*" required>

2 个答案:

答案 0 :(得分:0)

Mb尝试在路径中不要使用空格, 例如,改为尝试“ ortoze-mideri steznici”,等等。

答案 1 :(得分:0)

尝试为$ target_path使用完整路径,例如。 “ c:\ app_path \ public_path \”