简体   繁体   English

PHP中的文件上传无效

[英]file upload in PHP is not working

I'm trying to upload a file to this directory: 我正在尝试将文件上传到此目录:

这个目录截图

with this code: 使用此代码:

<?php
$target_dir = "../../assets/image/product/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$image = $_POST['fileToUpload'];
$add = $_POST['add'];
$merk = $_POST['merk'];
$category = $_POST['category'];
$color = $_POST['color'];
$size = $_POST['size'];
$price = $_POST['price'];
$stock = $_POST['stock'];

if(isset($add)){
    move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file);
    mysql_query("INSERT INTO item VALUES('','$merk','$category','$color','$size','$price','$stock','$image')");
    echo "<script>window.location='item.php';</script>";
}
?>

but the uploaded file is not appearing in target directory 但上传的文件没有出现在目标目录中

Basically you have to find what error messages for. 基本上你必须找到什么错误消息。

add this line at the top of your code 在代码顶部添加此行

error_reporting(E_ALL);

and this one, if it's your local (not live) server 如果它是你的本地(非现场)服务器,那么这一个

ini_set('display_errors',1);

so, you will be able to see the errors on screen 所以,你将能够在屏幕上看到错误

Finally, for the files upload make sure that upload folder have full permission and you have to check $_FILES['fileToUpload']['error']) first. 最后,对于文件上传,请确保上传文件夹具有完全权限,并且您必须首先检查$_FILES['fileToUpload']['error']) it it's not 0, refer to the manual page for the message. 它不是0,请参阅消息的手册页。

确保已将enctype="multipart/form-data"到html文件中的<form>元素

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

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