我创建了一个网站,您可以将图片/文件上传到服务器,数据库会保存文件所在的位置。一切都保存在数据库中,但文件不会保存在我的服务器中,该怎么办?
<?php
$target = "bilder/";
$target = $target . basename( $_FILES['photo']['name']);
$name=$_POST['name'];
$desc=$_POST['desc'];
$pic=($_FILES['photo']['name']);
mysql_connect("localhost", "root", "") or die(mysql_error()) ;
mysql_select_db("david") or die(mysql_error()) ;
mysql_query("INSERT INTO `bild` VALUES ('$name', '$desc', '$pic', NOW())") ;
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
{
echo "The file ". basename( $_FILES['photo']['name']). " was uploaded! <br>";
echo "Click " . '<a href="bilder.php">here</a>' . " to see all uploaded files<br>";
echo "Click " . '<a href="test.html">here</a>' . " to upload more files!";
}
else {
echo "Error.";
}
?>
答案 0 :(得分:1)
可能被拒绝,在php.ini文件中打开“display_errors = On”,可能会收到警告信息。
尝试"chmod 777 bilder/"
答案 1 :(得分:0)
确保将enctype属性添加到将其提交到处理脚本的表单中。
执行var_dump $ _FILES ['photo'] ['name']以确保文件也被发送到您的处理中。