如何上传mp3文件 [英] How to upload mp3 files
问题描述
我正在尝试获取一个将mp3或某些图像文件上传到文件夹的表单.
使用下面的代码,我可以上载图像文件,但是当我尝试上载mp3时,出现错误Undefined index: file in C:\wamp\www\recordlabel\inc\soundclips.php on line 6
,并且代码从我的else块中回显invalid file
.谁能提供帮助?
Im trying to get a form to upload mp3 or certain image files to a folder.
Using below code I can upload the image files ok, but when i try to upload an mp3 i get the error Undefined index: file in C:\wamp\www\recordlabel\inc\soundclips.php on line 6
and the code echos invalid file
from my else block. can anyone offer assistance?
$allowedExts = array("mp3", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if ((($_FILES["file"]["type"] == "audio/mp3")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/x-png")
|| ($_FILES["file"]["type"] == "image/png"))
&& in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
if (file_exists("../soundclips/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"../soundclips/" . $_FILES["file"]["name"]);
echo "Stored in: " . "../soundclips/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
这是我的表格
<form class='form1' action='../inc/soundclips.php' method='post'
enctype='multipart/form-data'>
<input type="hidden" name="id" value="<?php echo $pid; ?>"/>
<b>Add Soundclip For <i><?php echo $e;?></i> </b>
<?php echo"<divclass='editimage'>";
echo "<img class='resizedimage' src='{$row['image']}' />";
echo"</div>";?><br />
<b>Song</b><br /><input type=text size='60' name='asong' /><br />
<input name='file' type="file" id="file" /><br />
<input type='submit' name='add' value='Add Soundclip' />
</form>
推荐答案
看起来您的mp3文件无法上传,因此$_FILES
数组中缺少该文件.这可能是由于其与图片文件相比的大小.
Looks like your mp3 file cannot be uploaded, so it is missing in $_FILES
array. That might be due to its size compared to image files.
请检查php.ini
中的upload_max_filesize
和post_max_size
设置,并允许其大小大于mp3文件.
Please check upload_max_filesize
and post_max_size
settings from your php.ini
and allow a greater size than your mp3 file.
这篇关于如何上传mp3文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!