Chrisj Posted November 15, 2014 Share Posted November 15, 2014 I'm trying to add a file size limit to my upload form-code (below) Is this correct? if ( $_FILES["file"]["size"] < 100000 If that's correct, do I need any additional code to make that line of code functional? $allowedExts = array("gif", "jpeg", "jpg", "pdf", "doc", "docx", "txt", "rtf", "png"); $temp = explode(".", $_FILES["file"]["name"]); $extension = strtolower( end($temp) ); if (!in_array($extension,$allowedExts)) { echo ("Error - Invalid File Name"); } $length = 20; $randomString = (time()); $thumbnail = $_SESSION['user_id'] . '-' . $randomString . "." . $extension; move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $thumbnail); $sql = "INSERT INTO videos ( filename ) VALUES( '$thumbnail' )"; mysql_query($sql); $file_location = '<a href="http://www.......com/upload/' . $thumbnail . '">' . $thumbnail . '</a>'; Thanks. I look forward to any help. Quote Link to comment Share on other sites More sharing options...
tryingtolearn Posted November 15, 2014 Share Posted November 15, 2014 it is and yes you have to make it functional I would do something like this, Create an array to hold error messages (Since you could possibly have two - 1 for a wrong extension and 1 for a file that's too large) Check to make sure the file meets the criteria $errors = array();//make an array to hold error messages $maxsize = 100000;//set your max upload size if($_FILES['file']['size'] > $maxsize) { $errors[] = 'Error - File must be less than xx megabytes.'; } if (!in_array($extension,$allowedExts)){ $errors[] = 'Error - Invalid File Name'; } if(count($errors) === 0) { //process your file upload here } else { foreach($errors as $error) { echo ''.$error.'<br />'; } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.