- Impact
- 8
Code:
<?
// Upload settings
$folder = "img/files/"; // Folder in which to store files
$maxlimit = 50000; // Set maximum file limit (in bits)
$allowed_ext = "jpg,gif,png,jpeg,bmp,png"; // Set allowed extensions (split using comma)
$overwrite = "no"; // Allow file overwrite? yes/no
$match = ""; // Clear match variable; for security purposes
$filesize = $_FILES['userfile']['size']; // Get file size (in bits)
$filename = strtolower($_FILES['userfile']['name']); // Get file name; make it all lowercase
if(!$filename || $filename==""){ // File not selected
$error = "- No file selected for upload.<br>";
}elseif(file_exists($folder.$filename) && $overwrite=="no"){ // Check if file exists
$error = "- File already exists: $filename<br>";
}
// Check if file size
if($filesize < 1){ // File is empty
$error .= "- File size is empty.<br>";
}elseif($filesize > $maxlimit){ // File is more than maximum
$error .= "- File size is too big.<br>";
}
$file_ext = preg_split("/\./",$filename); // Split filename at period (name.ext)
$allowed_ext = preg_split("/\,/",$allowed_ext); // Create array of extensions
foreach($allowed_ext as $ext){
if($ext==$file_ext[1]) $match = "1"; // File is allowed
}
// File extension not allowed
if(!$match){
$error .= "- File type isn't allowed: $filename<br>";
}
if($error){
print "Error trying to upload file:<br> $error"; // Display error messages
}else{
if(move_uploaded_file($_FILES['userfile']['tmp_name'], $folder.$filename)){ // Upload file
print "Success! The file has been uploaded: Http://www.freephotohost.co.uk/img/files/$filename";
}else{
print "Error! File size might exceed upload limit of server. Try again."; // Display error
}
}
?>
How can I make it so the files names are changed?







