Hello I am having a really hard time with move_uploaded_file
I am trying to output an error when the uploaded file is too big. My server max upload is set to 100Mb and I am trying to set the limit to 10Mb. If I upload a smaller file it works, if I try to upload a bigger file the file doesn't get uploaded (as expected) but I am unable to output the error I want to output.
It seems that $_FILES is empty and because it is empty I can't check for the existence of the upload with is_uploded_file or file_exists (I have no argument for the two functions).
I read the manual and all the comments... somebody commented that if the file is too move_uploaded_file will just die and not return an error and that is what seems to be happening.
Does anyone know how to work around this?
Here's my code so far:
if ( $_POST && empty($_FILES['tbs_mp3']['name']) ) {
// nothing to upload
echo '<br /><br /><span style="background-color:orange;">'.$tbs_lng['upld_not'].'</span>'.$rn;
} else if ( $_POST && strtolower(substr($_FILES['tbs_mp3']['name'],-3)) == 'mp3' ) {
// correct extension
if ( move_uploaded_file($_FILES['tbs_mp3']['tmp_name'], $target_path.str_replace(' ','_',$_FILES['tbs_mp3']['name'])) ) {
// file uploaded succesfully
echo '<br /><br /><span class="approved">'.$tbs_lng['upld_ok'].'</span><br /><br />'.$rn;
echo 'The file you just uploaded is now called: <b>'.str_replace(' ','_',$_FILES['tbs_mp3']['name']).'</b><br />';
} else {
// file too big
echo '<br /><br /><span class="error"><b>'.$tbs_lng['upld_err1'].' '.($_POST['MAX_FILE_SIZE'] / 1000000).'Mb '.$tbs_lng['upld_err2'].'</b></span><br />'.$rn;
}
} else if ( $_POST && strtolower(substr($_FILES['tbs_mp3']['name'],-3)) != 'mp3' ) {
// wrong extension (no upload takes place)
echo '<br /><br /><span class="error"><b>'.$tbs_lng['upld_mp3ext_err'].'</b></span><br />'.$rn;
}