du9826 2011-10-19 17:28
浏览 15
已采纳

我的php上传脚本没有结果?

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 ?

  • 写回答

1条回答 默认 最新

  • donglengyuan6826 2011-10-19 17:33
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器