當我運行下面的代碼,它說爲什麼我不能在php中更改輸入文件名?
「通知:未定義指數:uploadFile在C:\ XAMPP \ htdocs中\ ImageTest \ processImage.php 17行」
但是,當我更換使用fileToUpload的uploadFile的每個實例似乎都可以工作。爲什麼?
processImage.php
<!DOCTYPE html>
<html>
<head>
<title> hello world</title>
</head
<body>
<?php
echo ' hi';
$servername="localhost";
$username="root";
$password="";
$dbname="db_ImageTest";
$conn=new mysqli($servername, $username, $password, $dbname);
echo $_FILES["uploadFile"]["name"];
/*
echo $image;
$image_name=$_FILES['image']['name'];
$image_size=getimagesize($_FILES['image']['tmp_name']);
if($image_size==FALSE){
echo 'failed';
}
$query="INSERT INTO mytable(image, name) VALUES(' {$image}', '{$image_name}')
*/
?>
</body>
</html>
的index.php
<!DOCTYPE html>
<html>
<body>
<form action="processImage.php" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="uploadFile" />
<input type="submit" value="Upload Image" name="submit"/>
</form>
</body>
</html>
當你加載html文件..表單中的文件沒有上傳,它試圖訪問它爲什麼會拋出警告,你可以解決'if($ _ POST){echo your code here};' –
Can你發佈var_dump($ _ POST,$ _FILES)的結果; –
echo var_dump($ _ POST,$ _FILES); (1){[「submit」] => string(12)「Upload Image」} array(1){[fileToUpload「] => array(5){[」name「] => string(9) 「pupil.png」[「type」] => string(9)「image/png」[「tmp_name」] => string(24)「C:\ xampp \ tmp \ phpEC09.tmp」[「error」] = > int(0)[「size」] => int(585)}} – user2350459