【发布时间】:2014-11-15 17:29:10
【问题描述】:
我目前在尝试让我的 php 上传表单正常工作时遇到一些问题。我收到此错误...抱歉,上传您的文件时出错。
如果 ftp 连接工作正常,我只是不确定什么会阻止上传。
这是php...
$target_dir = "photos/";
$target_file = $target_dir . basename($_FILES["photo"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["photo"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
if ($_FILES["photo"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
} else {
if (move_uploaded_file($_FILES["photo"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["photo"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
$res=mysql_query("INSERT INTO Photos (image_name, thumb, photo, photo_alt) VALUES
('$_POST[image_name]', '$_POST[thumb]', '$_POST[photo]', '$_POST[photo_alt]')");
if (array_key_exists ('check_submit', $_POST ))
if (!$res) {
die('Invalid query: ' . mysql_error());
}
?>
和 html....
<input type ="hidden" value="1" name="check_submit" enctype="multipart/form-data"/>
Please Enter Name: <input type ="text" name="image_name" /> <br />
Tags: <input type ="text" name="photo_alt" /> <br />
thumb <input type="file" name="thumb" /><br/>
image <input type="file" name="photo" /><br/>
<input type ="submit" name"Submit" /><br />
</form>
感谢阅读。
【问题讨论】:
-
可能是权限问题;您的脚本是否对 /photos/ 有写入权限?