我有一个表单,应该允许用户上传一个图像,该图像将其文件保存到文件夹unitimages
中,并且filename
将其保存到我的MSSQL表列中photo
在表used_trailers1
中。到目前为止,当我在表单上点击提交时,图像4010737399_df630e8a3a_o.jpg
在照片输入中。我被发送到添加.php页面,并显示以下错误:
Warning: mssql_query() [function.mssql-query]: message: Incorrect syntax near '`'. (severity 15) in D:Hostinga90htmlsalesadd.php on line 25
Warning: mssql_query() [function.mssql-query]: Query failed in D:Hosting4ahtmlsalesadd.php on line 25
Warning: move_uploaded_file(unitimages/4010737399_df630e8a3a_o.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in D:Hosting4ahtmlsalesadd.php on line 28
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'D:Tempphpphp4D71.tmp' to 'unitimages/4010737399_df630e8a3a_o.jpg' in D:Hosting45a90htmlsalesadd.php on line 28
Sorry, there was a problem uploading your file.
这是我输入图像的表单页面代码:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<form enctype="multipart/form-data" action="add.php" method="POST">
Name: <input type="text" name="title"><br>
E-mail: <input type="text" name = "description"><br>
Phone: <input type="text" name = "make"><br>
Photo: <input type="file" name="photo"><br>
<input type="submit" value="Add">
</form>
</body>
</html>
以下是 add.php 页面的完整 PHP 页面代码:
<?php
//This is the directory where images will be saved
$target = "unitimages/";
$target = $target . basename( $_FILES['photo']['name']);
//This gets all the other information from the form
$name=$_POST['title'];
$email=$_POST['description'];
$phone=$_POST['make'];
$pic=($_FILES['photo']['name']);
// Connects to your Database
$conn = mssql_connect('garce.com','Gdr','Rg1!');
mssql_select_db('Ggler',$conn);
if(! mssql_connect )
{
die('Could not connect: ' . mssql_get_last_message());
}
//Writes the information to the database
$mmssql_query = ("INSERT INTO `used_trailers1` VALUES ('$name', '$email', '$phone', '$pic')") ;
$Test=mssql_query($mmssql_query, $conn);
//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.";
}
?>
感谢您的任何帮助。非常感谢所有帮助。
似乎您有 2 个问题。一个是MSSQL错误。另一个是权限错误。
1) 尝试删除 used_trailers1
周围的反引号。
2) 仔细检查您的 Web 服务器运行的用户是否在您尝试移动文件的目录中也具有写入权限。