我想将图像上传到文件夹/images并保留其名称

这就是我得到的:

html

<form action="script.php" method="post" enctype="multipart/form-data">
   <input type="file" name="mynewimage">
   <input type="submit">
</form>


的PHP

if (!empty($_FILES['mynewimage']['name'])) {
move_uploaded_file($_FILES['mynewimage']['tmp_name'], "images/" . $_FILES["mynewimage"]["name"]);
}


/ images文件夹是777

错误说:UPLOAD_ERR_NO_FILE

Value: 4; No file was uploaded.

最佳答案

您应该检查上传错误:

if (isset($_FILES['mynewimage']) && $_FILES['mynewimage']['error']==0) {
    ....
}else{
    die('Error uploading, code '.$_FILES['mynewimage']['error']);
}


检查错误代码here

关于php - 用php上传简单图片无法正常工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22015899/

10-10 00:26