我正在尝试将文件上传到我知道可行的预先存在的表单,并且除了文件上传部分之外还有。
基本上,我不确定错误以及如何解决它。根据我对代码的理解,输出只是我放在那里的输出
我从以下代码获得以下输出:
输出
Array ( [chart-image] => Array ( [name] => Chart example.jpg [type] => image/jpeg [tmp_name] => /tmp/php5iGbQD [error] => 0 [size] => 50222 ) ) CAN'T MOVE FILE
FORM
<form id="<?php echo $type ?>-trade" enctype="multipart/form-data" method='post' action='<?php echo $url; ?>'>
*snip*
<input type="hidden" name="MAX_FILE_SIZE" value="52428800" />
<input name="chart-image" type="file" />
*snip*
</form>
行动页
snip print_r($_FILES);if($_FILES['chart-image']['error'] == '0'){ $uploaddir = '/images/charts/'; $file = basename($_FILES['chart-image']['name']); $uploadfile = $uploaddir . $file; if(file_exists($_FILES['chart-image']['tmp_name'])){ if (move_uploaded_file($_FILES['chart-image']['tmp_name'], $uploadfile)) { echo "GOOD"; } else { echo "CAN'T MOVE FILE"; } } else { echo "ERROR"; } } else{ echo "Error In Uploading File"; } *snip*
其他信息
php.ini
<form>
和php.ini
答案 0 :(得分:0)
我试过这个并且工作正常:
<?php
//print_r($_FILES);
if($_FILES['chartimage']['error'] == '0'){
$uploaddir = 'images\\';
$file = ($_FILES['chartimage']['name']);
$uploadfile = $uploaddir . $file;
if(file_exists($_FILES['chartimage']['tmp_name'])){
move_uploaded_file($_FILES['chartimage']['tmp_name'], $uploadfile);
} else {
echo "ERROR";
}
}
else{
echo "Error In Uploading File";
}
?>
当你打印出$ uploadfile = $ uploaddir时。 $文件; echo $ uploadfile;你的代码,我得到:images / C:\ WINDOWS \ Temp \ php76.tmp这是问题的根源。