无法将文件上传到服务器“move_uploaded_file()”错误

时间:2014-02-28 09:20:42

标签: php mysql file upload

我可以使用计算机将文件上传到服务器,但不能与其他人一起上传。我已经将目录权限更改为777但它仍然无法正常工作。

<?php 
$required = array('name', 'desc');
$error = false;

foreach($required as $field) {
  if (empty($_POST[$field])) {
    $error = true;
  }
}

if ($error) {
  header('Location: error1.php');
} else {
  if (empty($_FILES['photo']['name'])) {
    header('Location: error2.php');
} else {

$target = "bilder/"; 
$target = $target . basename( $_FILES['photo']['name']); 

$name=$_POST['name'];  
$desc=$_POST['desc']; 
$pic=($_FILES['photo']['name']); 

mysql_connect("localhost", "root", "si") 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)) { 
   header('Location: success.php');
} 
else { 
   header('Location: error3.php');
} 
}
}
?> 

当我上传文件时,我会收到以下错误消息:

if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) { 
   header('Location: success.php');
} 
else { 
   header('Location: error3.php');
} 

任何人都知道问题可能是什么?感谢任何帮助!

html表单:

<div id="form">
        <form enctype="multipart/form-data" action="add.php" method="POST"> 
            <br>
            <br>
            Titel:<br> <input type="text" name="name" style="width: 300px; height: 50px; font-size: 20px;"><br><br><br>
            Beskrivning: <br><textarea cols="100" rows="8" name="desc" style="font-size: 15px;"></textarea><br><br><br>
            Bild:<br> <input type="file" name="photo" style="height: 40px;"><br><br><br>
            <input type="submit" value="Lägg till" style="height: 40px;"> 
        </form>
</div>

0 个答案:

没有答案