简体   繁体   中英

my php upload script no result ?

i have problem on my php file upload script , i am trying to upload a file , then store a location on mysql database.

the problem is when i am trying to upload any file , the action.php doesn't give me any message whether it success or failed !

here is my html form:

<form enctype="multipart/form-data" action="add.php" method="POST"> 
 Name: <input type="text" name="name"><br> 
 E-mail: <input type="text" name = "email"><br> 
 Phone: <input type="text" name = "phone"><br> 
 Photo: <input type="file" name="photo"><br> 
 <input type="submit" value="Add"> 
 </form>

here is my add.php code:

     <?php 

 //This is the directory where images will be saved 
 $target = "/images/"; 
 $target = $target . basename( $_FILES['photo']['name']); 

 //This gets all the other information from the form 
 $name=$_POST['name']; 
 $email=$_POST['email']; 
 $phone=$_POST['phone']; 
 $pic=($_FILES['photo']['name']); 

 // Connects to your Database 
 mysql_connect("localhost", "root", "123123") or die(mysql_error()) ; 
 mysql_select_db("bom") or die(mysql_error()) ; 

 //Writes the information to the database 
 mysql_query("INSERT INTO `bom` VALUES ('$name', '$email', '$phone', '$pic')") ; 

 //Writes the photo to the server 
 if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) 
 { 

 //Tells you if its all ok 
 echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; 
 } 
 else { 

 //Gives and error if its not 
 echo "Sorry, there was a problem uploading your file."; 
 } 
 ?>

mysql conntection is working 100%, i have make sure of that , also i have a folder called " images " on my script folder , where is the problem ?

You've assumed that the file upload actually worked. You should have at least some minimal error handling before you do anything with the upload:

if ($_FILES['uploadedfile']['error'] !== UPLOAD_ERR_OK) {
    die("Upload failed with error code " . $_FILES['uploadedfile']['error'])
}

The error codes are document here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM