2015-08-14 23 views
1

我一直向前看这个,找不到解决方案。我正在尝试上传的文件没有移动。我使用WAMP和我的根文件夹是C:\ wamp \ wwwPHP试图用move_uploaded_file移动文件

我已检查目录是否存在于PHP中,并放入一个脚本,如果它不存在它应该被创建,这是可行的,但仍然没有移动文件。我究竟做错了什么?

的形式为:

<form enctype="multipart/form-data" action="upload.php" method="POST"> 
<input type="hidden" /> 
Choose a file to upload: <input name="uploadedfile" type="file" /><br /> 
<input type="submit" value="Upload File" /> 
</form> 

upload.php的

$target_path = "uploads/" ; 
if(!file_exists($target_path)) { 
    mkdir($target_path, 0755, true); 
    echo "The directory was created"; 
} 
$tmp_name = $_FILES['file']['tmp_name']; 
$target_path = $target_path . basename($_FILES['uploadedfile']['name']); 
echo $target_path; 

if(move_uploaded_file($tmp_name, $target_path)) { 
    echo "The file ". basename($_FILES['uploadedfile']['name']). 
    " has been uploaded"; 
} else{ 
    echo "There was an error uploading the file, please try again!"; 
} 
+1

你只是假设上传成功。你需要在$ _FILES ** FIRST **中检查'['error']'',然后执行任何其他操作。 –

+1

你也可以用你的HTML代码吗?并且是'['error']'可以提供更多信息 – Yogesh

+0

谢谢。我在上面的问题中添加了表单,然后使用了print_r($ _ FILES);检查变量,但没有错误:Array([uploadedfile] => Array([name] => ts.txt [type] => text/plain [tmp_name] => C:\ wamp \ tmp \ php48A8.tmp [error] => 0 [size] => 803390)) – Wilest

回答

0

尝试改变,

$tmp_name = $_FILES['file']['tmp_name']; 

$tmp_name = $_FILES['uploadedfile']['tmp_name']; 
+0

谢谢,现在我觉得自己像个白痴!我一直在俯视着整个时间! – Wilest

相关问题