move_uploaded_file返回错误代码0

时间:2012-05-25 13:15:37

标签: php

请参阅本文末尾的代码段...

在尝试使用move_uploaded_file将tmp文件移动到另一个目录时,我始终返回错误代码0。我已确认该目录存在,并且权限设置为775。我还检查了服务器管理员,他说他没有在错误日志中看到任何可以解释我遇到的问题的错误。

使用move_uploaded_file时如何绕过错误代码0?

$audio_dir  = "/mbc/data/audio/";

if (isset($_POST['upload_audio'])) {

    $title      = mysql_real_escape_string($_POST['audio_title']);
    $category   = mysql_real_escape_string($_POST['audio_category']);
    $audio_name = basename($_FILES['audio_file']['name']);
    $uploadfile = $audio_dir.$audio_name;

    $query = mysql_query("SELECT COUNT(*) FROM media where path = '" . $audio_name . "'");
    $result = mysql_result($query, 0, 0);

    if (($title == '') || ($title == NULL) ||
        ($category == '') || ($category == NULL) ||
        ($audio_name == '') || ($audio_name == NULL)) {
        echo "<span class='error'>Title, Category and Audio file are required fields</span>";                            
    } else if ($result > 0) {
    echo "<span class='error'>Media $audio_name already exists - please upload with a different name</span>";                               
    } else if (ctype_alpha($category) === false) {
        echo "<span class='error'>Category can only have letters (no spaces, commas, numbers, etc...)</span>";              
    } else if (ctype_alnum(substr($audio_name, 0, strpos($audio_name, '.'))) === false) {
    echo "<span class='error'>Bad filename - $audio_name - can only contain letters and numbers (i.e. 'HowGreatThouArt.mp3')</span>";
    } else {
        if (move_uploaded_file($_FILES['audio_file']['tmp_name'], $uploadfile)) {
            $queryInsertAudio = "insert into media (title, path, category ) values ('{$title}','{$audio_name}','{$category}')";
            $result = mysql_query($queryInsertAudio);
            if ($result) {
                echo "<span class='success'>AUDIO $audio_name UPLOADED SUCCESSFULLY</span>";
            } else {
                echo "<span class='error'>FAILED TO INSERT RECORD FOR $audio_name - PLEASE CONTACT ADMINISTRATOR</span>";
            }
        } else {
            echo "<span class='error'>FAILED TO UPLOAD AUDIO $audio_name - PLEASE CONTACT ADMINISTRATOR<br />" . 
                 "ERROR CODE = " . $_FILES['audio_file']['error'] . "<br />" . 
                 "Temp filename=" . $_FILES['audio_file']['tmp_name'] . "<br />" .
                 "Uploadfile=" . $uploadfile . "<br />" .
                 print_r($_FILES) . 
                "</span>";
        }
    }
}

1 个答案:

答案 0 :(得分:0)

OOPS ...这是我的$audio_dir文件路径已关闭...已修复,现在我可以上传没有问题...