2017-06-01 63 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)