2017-06-01 24 views
0

好傢伙,請幫忙! 我有我的項目的問題,我跟着就如何上傳(https://www.youtube.com/watch?v=Ipa9xAs_nTg)這些步驟,但什麼是錯的。
錯誤是注意:上傳照片MySQL和顯示器使用PHP

未定義指數:tmp_name的值在C:\ XAMPP \ htdocs中\ LDEVERACATERING \ upload_process.php第16行

這裏是我的upload.html

<!DOCTYPE html> 
     <html> 
     <head> 
      <script src="jquery-3.2.1.min"></script> 
      <script src="jquery-migrate-1.4.1.min"></script> 
     <title> 
     Image Upload 
     </title> 
     <link rel="stylesheet" type="text/css" href="style.css"> 
     </head> 
     <body> 
     <div id="content"> 
       <form method="POST" action="upload_process.php" enctype="multipart/form-data"> 
        <input type="hidden" name="size" value="1000000"/> 
        <div> 
         <input type="file" name="image"/> 
        </div> 
        <div> 
         <textarea name="text" cols="40" rows="4" placeholder="Say something about this image..."></textarea> 
        </div> 
        <div> 
         <input type="submit" name="upload" value="Upload Image"/> 
        </div> 
       </form> 

     </div> 
     </body> 
     </html> 

這裏是我的upload_process.php

<?php 
$msg = ""; 
//if upload button is pressed 
if (isset($_POST['upload'])) { 
    //path to store the upload image 
    $target = "photos/".basename($_FILES['image']['name']); 
    //connect to database 
    $db = mysqli_connect("localhost", "root", "", "catering_info"); 
} 
//get all the submitted date from the form 
$image = $_FILES['image']['name']; 
$text = $_POST['text']; 

$sql = "INSERT INTO photos_upload(image, text) VALUES('$image', '$text')"; 
mysqli_query($db, $sql); //stores the submitted date into the database table: images 
//now let's move the upload image into the folder: photos 
if (move_uploaded_file($_FILES['tmp_name']['name'], $target)) { 
    $msg = "Image uploaded successfully"; 
} 
else 
{ 
    $msg = "There was a problem uploading image"; 
} 
?> 

請幫助我,我真的需要它。另外我還是新來這個,我剛開始網絡PROG過去的3周:(非常感謝你!

+0

閱讀本教程:https://www.w3schools.com/php/php_file_upload.asp –

回答

0

請試試這個

<?php 
    if(isset($_FILES['image'])){ 
     $errors= array(); 
     $file_name = $_FILES['image']['name']; 
     $file_size =$_FILES['image']['size']; 
     $file_tmp =$_FILES['image']['tmp_name']; 
     $file_type=$_FILES['image']['type']; 
     $file_ext=strtolower(end(explode('.',$_FILES['image']['name']))); 

     $expensions= array("jpeg","jpg","png"); 

     if(in_array($file_ext,$expensions)=== false){ 
     $errors[]="extension not allowed, please choose a JPEG or PNG file."; 
     } 

     if($file_size > 2097152){ 
     $errors[]='File size must be excately 2 MB'; 
     } 

     if(empty($errors)==true){ 
     move_uploaded_file($file_tmp,"images/".$file_name); 
     echo "Success"; 
     }else{ 
     print_r($errors); 
     } 
    } 
?> 
+0

這工作!謝謝!! –

0

通過更換你的代碼試試這個

move_uploaded_file($_FILES['tmp_name']['name'], $target) 

有了這些

move_uploaded_file($_FILES['image']['tmp_name'], $target)