I've created a simple upload form which renames the file to some random numbers but I keep encountering problems when adding file size/extension limits. This is the current code: function findexts ($filename) { $filename = strtolower($filename) ; $exts = split("[/\\.]", $filename) ; $n = count($exts)-1; $exts = $exts[$n]; return $exts; } $ext = findexts ($_FILES['uploaded']['name']) ; $ran = rand () ; $ran2 = $ran."."; $target = "upload/"; $target = $target . $ran2.$ext; if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "http://###.###.com/###/dl.php?file=".$ran2.$ext; //removed URL } else { echo "Sorry, there was a problem uploading your file."; } Code (markup): Could anyone possibly help to add the above requirements in? Cheers in advance.
$allowed_ext = array('doc','txt','rtf'); $ext = end(explode('.',$_FILES['uploaded']['name']); $ran2 = rand()."."; $target = "upload/"; $target = $target . $ran2.$ext; if($_FILES['uploaded']['size'] > 1048576){ $message = 'File over 1048576 bytes';} if($message == NULL && !in_array($ext,$allowed_ext)){ $message = 'File extension not allowed';} if($message == NULL){ if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { $message = "http://###.###.com/###/dl.php?file=".$ran2.$ext; //removed URL } else { $message = "Sorry, there was a problem uploading your file."; } } echo $message; PHP: Peace,
Parse error: syntax error, unexpected ';' in inc.php on line 24 Line 24 is $ext = end(explode('.',$_FILES['uploaded']['name']); PHP:
There is a missing ")" Change it to: $ext = end(explode('.',$_FILES['uploaded']['name'])); Code (markup): Peace,