English 中文(简体)
move_ uploaed_file 返回 0 的错误代码
原标题:move_uploaded_file returns an error code of 0
  • 时间:2012-05-25 13:15:37
  •  标签:
  • php

请看此文章结尾处的代码片断...

当试图使用 move_uploaded_files 将 tmp 文件移动到另一个目录时,我总是会收到一个0的错误代码。 我确认目录存在, 权限设置为 775 。 我还检查了服务器管理员, 他说他没有看到错误日志中的任何错误, 从而可以解释我的问题 。

使用 move_uploaded_files 时如何绕过 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>";
        }
    }
}
最佳回答

OOPS... 这是我的 $audio_dir 文件路径关闭... fixed that up and now I can to上传没有问题...

问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签