在谷歌环顾一段时间后,我卡住了= /有人可以帮我吗?php脚本上传MP3文件不会玩球
似乎与我尝试的大多数文件一起工作,但.mp3文件除外。
的(X)HTML
<html>
<body>
<form enctype="multipart/form-data" action="upload.php" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="71680000" />
Choose a file to upload: <input name="uploaded_file" type="file" />
<input type="submit" value="Upload" />
</form>
</body>
</html>
的PHP
<?php
//Сheck that we have a file
if((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0)) {
//Check file extension and size
$filename = basename($_FILES['uploaded_file']['name']);
$ext = substr($filename, strrpos($filename, '.') + 1);
if (($ext == "mp3") && ($_FILES["uploaded_file"]["type"] == "audio/mpeg") &&
($_FILES["uploaded_file"]["size"] < 71680000)) {
//Determine the path to which we want to save this file
$newname = dirname(__FILE__).'/up/'.$filename;
//Check if the file with the same name is already exists on the server
if (!file_exists($newname)) {
//Attempt to move the uploaded file to it's new place
if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname))) {
echo "It's done! The file has been saved as: ".$newname;
} else {
echo "Error: A problem occurred during file upload!";
}
} else {
echo "Error: File ".$_FILES["uploaded_file"]["name"]." already exists";
}
} else {
echo "Error: Only .mp3 files under are accepted for upload";
}
} else {
echo "Error: No file uploaded";
}
?>
编辑:这是后续代码var_dump($ _ FILES)的输出;
array(1) {
["uploaded_file"]=>
array(5) {
["name"]=>
string(17) "03-AsWeTravel.mp3"
["type"]=>
string(0) ""
["tmp_name"]=>
string(0) ""
["error"]=>
int(1)
["size"]=>
int(0)
}
}
什么是错误?你面临什么问题?更多信息..你得到哪些错误回声 – Stewie 2010-09-29 19:17:39
你确定mime类型是audo/mpeg吗? – methodin 2010-09-29 19:20:16
这是否仅针对.mp3文件或其他文件类型(包括二进制和文本文件 - 例如,您可以将脚本更改为接受其他文件类型,并尝试使用较大的.jpg文件进行检查)。 – 2010-09-29 19:20:34