Jump to content

upload script works for images but not mp3


hellonoko

Recommended Posts

My below code works perfectly fine for uploading images. But when I change the file type to audio/mpeg for mp3s does it does not work.

 

Does not error either.

 

Any ideas?

 

Thanks for your time.

 

<?php

//include "admin_menu.php";

ini_set('display_errors', 1);
error_reporting(E_ALL);

?>


<title>Upload Image</title><form name="form1" method="post" action="upload_image.php" enctype="multipart/form-data">
<input name="imagefile" type="file" size="100">

<input type="submit" name="Submit" value="Upload"> 


<?php

//$submit = $_POST['Submit'];
if (empty($_FILES['imagefile']))
	{
		echo "<br><br>";
		echo "Please choose a image to upload...";
		die;
	}

if(!empty( $_POST['Submit'] ))
{

	//If the Submitbutton was pressed do:

	if ($_FILES['imagefile']['type'] == "audio/mpeg")
	{

		$_FILES['imagefile']['name'] = str_replace(" ", "_", $_FILES['imagefile']['name']);

		copy ($_FILES['imagefile']['tmp_name'], "music/".$_FILES['imagefile']['name']) or die ("Could not copy"); 

		echo "<br><br>"; 
        	//echo "<b>Name: </b>".$_FILES['imagefile']['name'].""; 
		//echo "<br>";
        	//echo "<b>Size: </b>".$_FILES['imagefile']['size'].""; 
        	//echo "<br>";
		//echo "<b>Type: </b>".$_FILES['imagefile']['type'].""; 
        	//echo "<br><br>";
		echo "<b>File Uploaded...</b>"; 
        }

 	else 
 	{
            echo "<br><br>";
            //echo "Could Not Copy... (".$_FILES['imagefile']['name'].")<br>";
		echo "Could Not Copy... <br>";
		die;
     	}
}   

echo "<br>";
//$image_to_thumbnail = $_FILES['imagefile']['name'];
//echo $image_to_thumbnail;

//include "resize_image.php";

//echo "<br>";
//echo "<img src=http://www.artbytoni.com/images/thumbs/t_".$image_to_thumbnail." />";
//echo "<br>";
//echo "<img src=http://www.artbytoni.com/images/full/".$image_to_thumbnail." />";
?> 

</form>

Link to comment
Share on other sites

Just throwing this out there (I'm not an expert with MIME) but perhaps you don't have the correct MIME type. Try printing $_FILES['imagefile']['type'] and record the value, then use that for the comparison. Or instead of the MIME type use the file extension. Get the position of the last period (function strrpos) then get all the letters after that (substr).

 

Edit:

 

I see, I think the problem is that the file dimension holds the file name not the MIME type.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.