php - How to upload mp3 files -
im trying form upload mp3 or image files folder.
using below code can upload image files ok, when try upload mp3 error undefined index: file in c:\wamp\www\recordlabel\inc\soundclips.php on line 6
, code echos invalid file
else block. can 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"] . " exists. "; } else { move_uploaded_file($_files["file"]["tmp_name"], "../soundclips/" . $_files["file"]["name"]); echo "stored in: " . "../soundclips/" . $_files["file"]["name"]; } } } else { echo "invalid file"; }
and form
<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 <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>
looks mp3 file cannot uploaded, missing in $_files
array. might due size compared image files.
please check upload_max_filesize
, post_max_size
settings php.ini
, allow greater size mp3 file.
Comments
Post a Comment