我正在尝试使用php上传脚本。但我不确定为什么$ _FILES似乎是空数组?有人可以解释下面我的脚本出了什么问题吗?
<html>
<body>
<?php
if (isset($_POST['Submit'])) {
$target_path = "/var/www/test/";
$target_path = $target_path . basename($_FILES['myupload']['name']);
if(!move_uploaded_file($_FILES['myupload']['tmp_name'], $target_path)) {
echo '<pre>';
print 'The $_FILES content is :';
print_r($_FILES);
var_dump($_FILES);
echo '<pre>';
print 'the target path is:' . $target_path;
echo '<pre>';
print 'the $_POST variable content is :';
print_r($_POST) ;
echo '<pre>';
echo 'Your image was not uploaded.';
echo '</pre>';
} else {
echo '<pre>';
echo $target_path . ' succesfully uploaded!';
echo '</pre>';
}
}
?>
<form method="POST" action="" enctype"multipart/form-data">
Choose an image to upload:
<br>
<input type="file" name="myupload">
<br>
<br>
<input type="submit" value="Upload(This_is_just_button_name_display)" name="Submit">
</form>
</body>
</html>
答案 0 :(得分:0)
不要转储$ _FILES我从来没有丢弃它并且对我来说很好。 尝试此代码并将PHP放在另一个文件中并将表单重定向到它并添加此行 在脚本的末尾
<META HTTP-EQUIV="REFRESH" CONTENT="0;URL=samplehtml.html">
所以最终的代码是:
<?php
if (isset($_POST['Submit'])) {
$target_path = "/var/www/test/";
$target_path = $target_path . basename($_FILES['myupload']['name']);
if(!move_uploaded_file($_FILES['myupload']['tmp_name'], $target_path)) {
echo '<pre>';
print 'The $_FILES content is :';
print_r($_FILES)
echo '<pre>';
print 'the target path is:' . $target_path;
echo '<pre>';
print 'the $_POST variable content is :';
print_r($_POST) ;
echo '<pre>';
echo 'Your image was not uploaded.';
echo '</pre>';
} else {
echo '<pre>';
echo $target_path . ' succesfully uploaded!';
echo '</pre>';
}
}
?>
它现在应该可以工作了。