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
https://forums.phpfreaks.com/topic/79767-solved-file-upload-help/
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

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.