Александр
Александр

Reputation: 65

500 (Internal Server Error) while uploading some filenames

I'm uploading some files, but sometimes i get an error 500. I just javascript to upload the file.

$userid = $_REQUEST['usr'];

$img = $_REQUEST['fileTopostUpload'];
$imgtype = substr($img,0,23);
$imgtypee = substr($img,0,22);
$imgtype2 = substr($img,5,10);
$imgtype3 = substr($img,5,9);

$filesize = $_REQUEST['filesize'];
$filename = $_REQUEST['filename'];
$filetype = $_REQUEST['filetype'];

$write_view = explode("-", $filename);

$artist = $write_view['0'];
$song = $write_view['1'];


$md5encoded = md5("$date$userid");
$ext = ".mp3";

$img = str_replace('data:audio/mp3;base64,', '', $img);
$img = str_replace('data:audio/mpeg;base64,', '', $img);
$img = str_replace(' ', '+', $img);
$data = base64_decode($img);




$check = mysql_query("SELECT * FROM songs WHERE songuploaduser = '$userid' AND songfilename = '$filename' AND songfilesize = '$filesize'");
$checkcheck = mysql_num_rows($check);

if($checkcheck == "0") {

$insert = mysql_query("INSERT INTO songs(
songartist,
songtitle,
songfilename,
songfilesize,
songuploaduser,
songuploaddate,
songpencoded
)VALUES(
'$artist',
'$song',
'$filename',
'$filesize',
'$userid',
'$date',
'$md5encoded$ext'
)");



$file = "$_SERVER[DOCUMENT_ROOT]/uploads/audio/$md5encoded$ext";
$success = file_put_contents($file, $data);


}

The files that gives error are like the onces below: 11 - Wamdue Project - King Of My Castle.mp3 01. Loreen - Euphoria.mp3 08. Fist Aid Kit - The Lion's Rour.mp3

but files that do work: Imran Khan - Amplifier.mp3 09. Lange Frans, Brutus, Negativ & Baas B - Je Bent Geen Tijger.mp3

I don't get it.. how can lets say one file give an error 500 and an other one does not?

Upvotes: 1

Views: 480

Answers (1)

Fran Naranjo
Fran Naranjo

Reputation: 51

As can be seen on comments, you have a memory error. Your PHP processes have 32 MB to run and it is not enough. Take a look to memory_limit directive in php.ini, or change it from the script by using something like ini_set('memory_limit','64M'); that will change from 32MB to 64MB for just that process.

You have to differentiate between a memory error (typically an "Allowed memory exhausted" error, explained before) and max allowed uploaded file size that can be changed with php.ini upload_max_filesize

Upvotes: 1

Related Questions