gpt4 book ai didi

php - 通过 php 和 html 表单上传文件的代码错误

转载 作者:行者123 更新时间:2023-11-29 23:48:04 25 4
gpt4 key购买 nike

我遇到以下代码错误,文件无法上传到服务器。有人可以看一下这两个文件并指出我哪里出错了,我知道我可能很厚,但任何帮助将不胜感激。

这些文件位于一个小型内部 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.";
}

最佳答案

改变

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

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

关于php - 通过 php 和 html 表单上传文件的代码错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25807370/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com