请参阅本文末尾的代码片段...
尝试使用move_uploaded_file
将 tmp 文件移动到另一个目录时,我始终返回错误代码 0。我已经确认该目录存在并且权限设置为 775。我还与服务器管理员核实过,他说他在错误日志中没有看到任何可以解释我遇到的问题的错误。
使用时如何绕过错误代码 0 move_uploaded_file
?
$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>";
}
}
}