
08-15-2010, 04:28 AM
|
|
Junior Member
|
|
Join Date: 08-15-10
Posts: 5
|
|
my upload form code WHAT I NEED TO MAKE HERE TO RENAME FILES AUTO WHEN UPLOADING
INDEX.PHP
HTML Code:
<form action="upload.php" method="post" enctype="multipart/form-data">
File: <input type="file" name="file" size="30"> <input type="submit" value="Upload">
</form>
UPLOAD.PHP
PHP Code:
<?php
// ==============
// Configuration
// ==============
$uploaddir = "uploads/images"; // Where you want the files to upload to - Important: Make sure this folders permissions is 0777!
$allowed_ext = "jpg, JPG, jpeg, JPEG, gif, GIF, bmp, BMP, PNG, MP3"; // These are the allowed extensions of the files that are uploaded
$max_size = "1500000"; // 50000 is the same as 50kb
$max_height = "250"; // This is in pixels - Leave this field empty if you don't want to upload images
$max_width = "230"; // This is in pixels - Leave this field empty if you don't want to upload images
// Check Entension
$extension = pathinfo($_FILES['file']['name']);
$extension = $extension[extension];
$allowed_paths = explode(", ", $allowed_ext);
for($i = 0; $i < count($allowed_paths); $i++) {
if ($allowed_paths[$i] == "$extension") {
$ok = "1";
}
}
// Check File Size
if ($ok == "1") {
if($_FILES['file']['size'] > $max_size)
{
print "Nuk pranohen foto me madhsi mbi 1.5 MB!";
exit;
}
// Check Height & Width
if ($max_width && $max_height) {
list($width, $height, $type, $w) =
getimagesize($_FILES['file']['tmp_name']);
if($width > $max_width || $height > $max_height)
{
print "Rezulucioni i fotografise eshte teper i madh!";
exit;
}
}
// The Upload Part
if(is_uploaded_file($_FILES['file']['tmp_name']))
{
move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.'/'.$_FILES['file']['name']);
}
print "Fotografia juaj u dergua me sukses, ajo do te vendohet ne web faqe pasi tė aprovohet nga Administratoret !";
} else {
print "Ju mund te ngarkoni vetem foto: Jpg, gif, bmp, png, mp3!";
}
?>
Last edited by HTMLBasicTutor; 08-15-2010 at 11:59 AM.
|