我尝试从Dialog(JQuery UI)窗口上传文件,如:
$( ".selector" ).dialog( "option", "buttons", [{ text: "Upload", click: function()
{ $( ".selector" ). append('<form action="../test/test_upload.php"
method="POST" name="getnamefile">
<input type="file" id="uploadfile" name="uploadfile">
<input type="submit" id="Submit" name= "Submit" value="Upload"></form>'); }....
和php parth:
error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);
$upfl = $_POST['uploadfile'];
$target_path = "../tmp/";
//if(is_uploaded_file($_FILES['uploadfile']['tmp_name']))
if(move_uploaded_file($_FILES['uploadfile']['tmp_name'], $target_path.$_FILES['uploadfile']['name'])) {
echo "The file ". basename( $_FILES['uploadfile']['name'])." has been uploaded";
} else{
echo $_FILES['uploadfile']['tmp_name'];
echo "There was an error uploading the file";
}
始终收到错误“上传文件时出错” 如果使用2个文件html和相同的PHP - 一切正常。 是什么原因?似乎所有都一样。 感谢。
答案 0 :(得分:2)
尝试在表单中添加enctype="multipart/form-data"
属性。