我使用下面的代碼上傳我的文件:PHP temp_name和move_uploaded_file錯誤
<?php include("./phpincludes/header.inc.php");
$status = "";
if(@$_POST['submit']){
$pic = @$_FILES['pic']['name'];
$pic_temp = @$_FILES['pic']['tmp_name'];
$pic_type = @$_FILES['pic']['type'];
$pic_size = @$_FILES['pic']['size'];
$doc1 = @$_FILES['doc1']['name'];
$doc1_temp = @$_FILES['doc1']['tmp_name'];
$doc1_type = @$_FILES['doc1']['type'];
$doc1_size = @$_FILES['doc1']['size'];
$doc2 = @$_FILES['doc2']['name'];
$doc2_temp = @$_FILES['doc2']['tmp_name'];
$doc2_type = @$_FILES['doc2']['type'];
$doc2_size = @$_FILES['doc2']['size'];
$name = stripcslashes(htmlspecialchars(urldecode($_POST['name'])));
$phone1 = stripcslashes(htmlspecialchars(urldecode($_POST['phone1'])));
$phone2 = stripcslashes(htmlspecialchars(urldecode($_POST['phone2'])));
$address = stripcslashes(htmlspecialchars(urldecode($_POST['address'])));
$sec = stripcslashes(htmlspecialchars(urldecode($_POST['sec_amount'])));
if($name != ""){
if($pic_size <= 1048576){
if (!$pic_temp) { // if file not chosen
echo "ERROR: Please browse for a file before clicking the upload button. ".$pic_temp;
}
$chars = "abcdefghijklmnopqrstuvrstwxyzABCDEFGHIJKLMNOPQRSTUVWXWZ";
$rand_dir_name = $name." ".substr(str_shuffle($chars), 0, 6);
mkdir("uploads/vendors/$rand_dir_name");
move_uploaded_file($doc1_temp, "uploads/vendors/$rand_dir_name/$doc1");
move_uploaded_file($doc2_temp, "uploads/vendors/$rand_dir_name/$doc2");
if(move_uploaded_file($pic_temp, "uploads/vendors/$rand_dir_name/$pic")){
echo "uploads/vendors/$rand_dir_name/$pic";
} else {
echo "move_uploaded_file function failed";
}
}else{
echo "Image size should be less than 1 MB!";
}
}else{
echo "Name is neccassary!";
}
}
?>
但問題是,它給我的錯誤,而上傳文件「錯誤:請瀏覽文件點擊上傳之前按鈕「。和'move_uploaded_file函數失敗'。我認爲這個問題是在文件前面的@,但是當我刪除它給我錯誤的未定義索引。
我的HTML表單: -
<form method='POST' name='form'>
<td><h4>Photo:</h4><input type='file' name='pic' accept="image/gif, image/jpeg, image/png"><h4>Full Name:</h4><input class='tableinput' type='text' placeholder='Name' name='name'></td>
<td><h4>Phone 1:</h4><input class='tableinput' type='text' placeholder='Phone' name='phone1'>
<h4>Phone 2:</h4><input class='tableinput' type='text' placeholder='Phone' name='phone2'></td>
<td>
<h4>Document 1:</h4>
<input type='file' name='doc1'>
<h4>Document 2:</h4>
<input type='file' name='doc2'>
</td>
<td><h4>Service:</h4><input class='tableinput' type='text' placeholder='Service' name='services'>
<h4>Address:</h4><input class='tableinput' type='text' placeholder='Address' name='address'></td>
<td> <input class='tableinput' type='text' placeholder='Sercurity Amount' name='sec_amount'></td>
<td >
<input type='submit' id='submit' name='submit' style='display:none;'/>
<i class='glyphicon glyphicon-ok-sign tableglyp blue' aria-hidden='true' onclick='submit()'>
</i>
</td>
</form>
請幫幫忙!
@抑制視圖中的錯誤/警告。似乎在某些情況下可能會取消$ _FILES值。所以請檢查您是否獲得'$ _FILES'值。通過使用'var_dump'或'print_r' – Thamaraiselvam
讓我們來看看你的表單HTML – Rasclatt
@Rasclatt在我的文章中看到我的html表單 – Zicsus