2010-09-29 72 views
0

在谷歌環顧一段時間後,我卡住了= /有人可以幫我嗎?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) 
    } 
} 
+0

什麼是錯誤?你面臨什麼問題?更多信息..你得到哪些錯誤回聲 – Stewie 2010-09-29 19:17:39

+0

你確定mime類型是audo/mpeg嗎? – methodin 2010-09-29 19:20:16

+0

這是否僅針對.mp3文件或其他文件類型(包括二進制和文本文件 - 例如,您可以將腳本更改爲接受其他文件類型,並嘗試使用較大的.jpg文件進行檢查)。 – 2010-09-29 19:20:34

回答

0

http://www.php.net/manual/en/features.file-upload.errors.php

UPLOAD_ERR_INI_SIZE 
Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini. 

你是如何處理從表單中MAX_FILE_SIZE?

嘗試改變

upload_max_filesize = 70M 

或任何你的最大尺寸應該是在你的php.ini。

+0

是的,我認爲它必須在php.ini中做最大尺寸,我複製粘貼到我的本地主機上的代碼,它完美的作品,MP3文件上傳到up文件夾。 – Christophe 2010-09-29 19:28:25

+0

我認爲你是對的。剛剛檢查phpinfo(),並意識到最大文件上傳大小爲2MB。假設我可以在.htaccess文件中更改它? – Dean 2010-09-29 19:39:44

+0

@methodin:剛剛注意到您對錶單的評論。謝謝! – Dean 2010-09-29 19:41:22

0

你有控制主機嗎?難道是MP3只是被封鎖?

我已經看到它之前在一個主要的ISP的免費網絡託管計劃...

+0

是的,自從我在自己的機器上運行腳本後,我完全可以控制它。 – Dean 2010-09-29 19:46:08