上传图片错误

时间:2012-10-05 12:46:15

标签: php javascript html mysql

好的我点击一个表单页面提交它处理div中的add.php'右键'你现在可以看到我遇到的问题是......

它处理add.php并将所有内容插入到数据库中但是...它没有插入图像URL或将图像上传到服务器,因为除了数据库和服务器中的图像之外,其他一切工作正常。

有没有解决方案?

我会放下两个脚本,任何解决方案都会很棒。

表单页面

<script type="text/javascript">
jQuery(document).ready(function($) {

   $("#Submit").click(function() {
var url = "add.php"; // the script where you handle the form input.

$.ajax({
   type: "POST",
   url: url,
   data: $("#myForm").serialize(), // serializes the form's elements.
   success: function(html){ $("#right").html(html); }
 });

return false; // avoid to execute the actual submit of the form.
 });
});
</script>

</head>
<body>
<div id="right">
</div>

<form action="add.php" method="post" enctype="multipart/form-data" id ="myForm">
 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="Upload" id="Submit">
</form>

add.php

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

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

 //Writes the information to the database 
 mysql_query("INSERT INTO `Employees` 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."; 
 } 

0 个答案:

没有答案
相关问题