2014-09-12 56 views
0

我遇到以下代码的错误,即文件无法上传到服务器。有人可以看看这两个文件,并建议我错了,我知道我可能很厚,但任何帮助将不胜感激。通过php和html表格上传文件的代码错误

这些文件位于小型内部Intranet上,因此我不关心将数据库连接和密码放入文件的事实。

正如我所说的任何帮助将不胜感激,因为我只收到最后的遗憾错误,没有信息传递给MySQL数据库。我可以让表单和代码在没有上传的情况下正常工作,但不能与。 我已检查上传目录和访问权限,一切正常。

HTML表单:

<form enctype="multipart/form-data" action="add.php" method="POST"> 
Model:<br /> <input type="text" name="model"><br> 
Size:<br /> <input type="text" name="size"><br> 
Total width:<br /> <input type="text" name="tot_width"><br> 
Internal width:<br /> <input type="text" name="int_width"><br> 
Total height:<br /> <input type="text" name="tot_height"><br> 
Frame height:<br /> <input type="text" name="fra_height"><br> 
Total depth:<br /> <input type="text" name="tot_depth"><br> 
Seat height:<br /> <input type="text" name="sea_height"><br> 
Seat depth:<br /> <input type="text" name="sea_depth"><br> 
Arm height:<br /> <input type="text" name="arm_height"><br> 
Std leg height:<br /> <input type="text" name="std_leg_height"><br> 
Image:<br /> <input type="file" name="image"><br> 
<input type="submit" value="Add"> 
</form> 

的PHP:

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

//Get all the other information from the form 
$model=$_POST['model']; 
$size=$_POST['size']; 
$totWidth=$_POST['tot_width']; 
$intWidth=$_POST['int_width']; 
$totHeight=$_POST['tot_height']; 
$fraHeight=$_POST['fra_height']; 
$totDepth=$_POST['tot_depth']; 
$seaHeight=$_POST['sea_height']; 
$seaDepth=$_POST['sea_depth']; 
$armHeight=$_POST['arm_height']; 
$stdLegHeight=$_POST['std_leg_height']; 
$pic=($_FILES['image']['name']); 

// Connect to Database 
mysql_connect("localhost", "databaseUser", "databasePassword") or die(mysql_error()) ; 
mysql_select_db("databaseName") or die(mysql_error()) ; 

//Write information to the database 
mysql_query("INSERT INTO `prod_dims` VALUES '$model', '$size', '$totWidth', '$intWidth', '$totHeight', '$fraHeight', '$totDepth', '$seaHeight', '$seaDepth', '$armHeight', '$stdLegHeight', '$pic'") ; 

//Put the image on the server 
if(move_uploaded_file($_FILES['image']['name'], $target)) 
{ 

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

//Give an error if its not 
echo "Sorry, there was a problem uploading your file."; 
} 

回答

0

变化

if(move_uploaded_file($_FILES['image']['name'], $target)) 

if(move_uploaded_file($_FILES["image"]["tmp_name"], $target)) 
+0

伟大的东西。总是感到沮丧,当你盯着年龄的东西,并直视通过明显的错误:) – Yeti 2014-09-12 11:52:54

+0

非常感谢您的帮助Ram :) – Yeti 2014-09-12 11:53:14

+0

我很高兴它帮助你 – 2014-09-12 12:04:50