Jump to content

[SOLVED] File upload help


prankstar008

Recommended Posts

The short version of my story is that I am trying to make a website where you can upload mp3 files.  Yes, I have permission to use the files that will be uploaded.  My problem is that the files don't upload.  I think I have confirmed that the issue is the file size as I can upload smaller files of all types.  I have changed my php.ini file to look like this

 


;;;;;;;;;;;;;;;;
; File Uploads ;
;;;;;;;;;;;;;;;;

; Whether to allow HTTP file uploads.
file_uploads = On

; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
;upload_tmp_dir =

; Maximum allowed size for uploaded files.
upload_max_filesize = 20M

 

my php file that handles uploads looks like this

<?php
$filename = $_FILES["theSong"]["name"];

$extension = substr($filename, strpos($filename,"."), strlen($filename));
/*
if ($extension != ".mp3" || $_FILES["theSong"]["size"] > 7000000){
echo "<script type = 'text/javascript'>
alert('ERROR: File must be an mp3 and smaller than 7MB');
</script>";
}
else{
*/
move_uploaded_file($_FILES["theSong"]["tmp_name"],
      "upload/" . $_FILES["theSong"]["name"]);
       echo "Error: " . $_FILES["file"]["error"];

//}


?>

 

*****NOTE that the check for size and type are currently commented out!!!!*****

 

For the reccord, the file typed that I have had success with were .pdf and .jpg

 

Specs:

Apache2

PHP5

Ubuntu Linux

Link to comment
Share on other sites

Try this code:

 

<?php
$filename = $_FILES["theSong"]["name"];
if ($FILES['theSong']['type']=="audio/mpeg") { 
	if($_FILES['theSong']['size'] > 7000000){
		move_uploaded_file($_FILES["theSong"]["tmp_name"], "upload/" . $_FILES["theSong"]["name"]);
       			if($_FILES["theSong"]["error"]==0) [
			print 'You have successfully uploaded ' . $_FILES["theSong"]["name"];
		}
		else {
			print "<script type = 'text/javascript'>" . $_FILES["theSong"]["error"] . "</script>";
		}
	}
	else {
		print "<script type = 'text/javascript'>alert('ERROR: File smaller than 7MB')</script>";
	}
}
else {
	print "<script type = 'text/javascript'>alert('ERROR: File must be an mp3 file')</script>";
}
?>

 

I have added in some better error checking and telling the user the exact problme.

 

And maybe you should try uping the file size because i doubt you could get a 7mb mp3 file even though it is compressed

Link to comment
Share on other sites

well for one thing. i changed the error checking mechanism use were using ($_FILES["file"]["error"]) so that it would actually show you anything by changing file to theSong and i did a better filetype checking. What eror did you get exactly and what is the website that this is on?

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.