我試圖上傳mp3格式文件到使用PHP的文件夾中。但是,這下面的編碼不起作用。請問有人能幫我嗎?將mp3文件上傳到文件夾不起作用
define("UPLOAD_DIR", "mp3_upload_folder/");
if (!empty($_FILES["myFile"]))
{
$myFile = $_FILES["myFile"];
if ($myFile["error"] !== UPLOAD_ERR_OK)
{
echo "<p>An error occurred.</p>";
exit;
}
// verify the file is a GIF, JPEG, or PNG
$fileType = exif_imagetype($_FILES["myFile"]["tmp_name"]);
// ensure a safe filename
$name = preg_replace("/[^A-Z0-9._-]/i", "_", $myFile["name"]);
// don't overwrite an existing file
$parts = pathinfo($name);
$sanjiv=$_POST['user_id'];
$name= $sanjiv.".".$parts["extension"];
// preserve file from temporary directory
$success = move_uploaded_file($myFile["tmp_name"],
UPLOAD_DIR . $name);
if (!$success) {
echo "<p>Unable to save file.</p>";
exit;
}
喲容易找到足夠的信息你可能會刪除檢查,看看文件是否是一個圖像。 – Luke