I want my php upload script to redirect to a page if the file is too big. I tried this: if (!isset($_FILES['userfile'])) exit; if (is_uploaded_file($_FILES['userfile']['tmp_name'])) { if ($_FILES['userfile']['size']>$max_size) { else { echo "<meta http-equiv=\"refresh\" content=\"0; url=REDIRECT.php\">; Code (markup): but it didn't work. Any ideas what I did wrong? Thanks.
Tried changing if ($_FILES['userfile']['size']>$max_size) to if (filesize($_FILES['userfile']['size'])>$max_size)
that wont work $_FILES['userfile']['size'] is an integer value not a file idk but try removing if (is_uploaded_file($_FILES['userfile']['tmp_name'])) { i don't know if its causing the problem but theres no point running this function
The if (!isset($_FILES['userfile'])) exit; if (is_uploaded_file($_FILES['userfile']['tmp_name'])) { if ($_FILES['userfile']['size']>$max_size) Code (markup): code is fine. It's what's after it; thats what's giving me errors, like "invalid syntax "else" on line blah blah. Is echoing a redirect the right move? Or should I make it a header? I don't know how to make it redirect if it exceeds $max_size.
I believe you should use something like this: if ($_FILES['userfile']['size']>$max_size){ header("Location:error.php?type=filesize"); } If you have already started to output your HTML before this part then you need to use: echo "<meta http-equiv=\"refresh\" content=\"0; url=REDIRECT.php\">; Then you need to add a "die;" so that if something goes wrong the script don't keep loading. Remember that If/Else statements are setup like if(){ }else{ } ]www.php.net/if Hope that helps.
I tried: if ($_FILES['userfile']['size']>$max_size){ header("Location:errorpage.php"); } Code (markup): but it takes me to a blank page. It doesn't redirect to the page I told it to.
is errorpage.php a file on your server? What is the URL in the address bar when the page is done loading?
Well try this: if ($_FILES['userfile']['size']>$max_size){ echo $_FILES['userfile']['size].">".$max_size; die; } This will echo out the values and will verify that the file was to large. If the page comes up blank then that means that the file was not to big. Let me know what you get.
Parse error: syntax error, unexpected T_STRING, expecting ']' in /home/[username]/public_html/engine.php on line 50
Opps sorry that was an error on my part. I was writing the code to faster here is the fixed version. if ($_FILES['userfile']['size']>$max_size){ echo $_FILES['userfile']['size'].">".$max_size; die; } What is the value of $max_size?
Okay so that means that the file was not bigger than 2097152 so you get a blank page. How big was the file that you uploaded?
try if ($_FILES['userfile']['size']>$max_size){ header("Location:errorpage.php"); die(); } else { //write here the code you need to run when the file is not bigger than $max_size } PHP: may be it is not bigger and because you just don't write code for processing not big files it shows a blank page of may be it is because the line if (!isset($_FILES['userfile'])) exit; PHP: if $_FILES['userfile'] is not existent it will die not showing any thing I recommend to make it show some thing like error message describing the error. at least in that case you will know which part of the code cause it to show a blank page
use this ob_start(); if (!isset($_FILES['userfile']) || !is_uploaded_file($_FILES['userfile']['tmp_name']) || $_FILES['userfile']['size']>$max_size ) { header("location:somepage.php"); exit(); } else { ///do something }