Page 1 of 1

problem in uploading

Posted: Thu Mar 03, 2005 8:13 am
by itsmani1

Code: Select all

<input type="file" name="file" size="30">
-----------------------------------
upload file

Code: Select all

// ==============
// Configuration
// ==============
$uploaddir = "uploads"; // Where you want the files to upload to - Important: Make sure this folders permissions is 0777!
$allowed_ext = "jpg, gif, png, pdf"; // These are the allowed extensions of the files that are uploaded
$max_size = "5000000"; // 50000 is the same as 50kb
$max_height = "800"; // This is in pixels - Leave this field empty if you don't want to upload images
$max_width = "800"; // This is in pixels - Leave this field empty if you don't want to upload images 
// Check Entension
$extension = pathinfo($_FILES&#1111;'file']&#1111;'name']);
$extension = $extension&#1111;extension];
$allowed_paths = explode(", ", $allowed_ext);
for($i = 0; $i < count($allowed_paths); $i++) &#123;
 if ($allowed_paths&#1111;$i] == "$extension") &#123;
 $ok = "1";
 &#125;
&#125;

// Check File Size
if ($ok == "1") &#123;
if($_FILES&#1111;'file']&#1111;'size'] > $max_size)
&#123;
print "File size is too big!";
exit;
&#125;

// Check Height & Width
if ($max_width && $max_height) &#123;
list($width, $height, $type, $w) = getimagesize($_FILES&#1111;'file']&#1111;'tmp_name']);
if($width > $max_width || $height > $max_height)
&#123;
print "File height and/or width are too big!";
exit;
&#125;
&#125;

// The Upload Part
if(is_uploaded_file($_FILES&#1111;'file']&#1111;'tmp_name']))
&#123;
move_uploaded_file($_FILES&#1111;'file']&#1111;'tmp_name'],$uploaddir.'/'.$_FILES&#1111;'file']&#1111;'name']);
&#125;
print "Your file has been uploaded successfully! Yay!";
&#125; else &#123;
print "Incorrect file extension!";
&#125;
echo "done";
exit;
------------------
by using above system: i m getting this as output:
----------
Incorrect file extension!done

Posted: Thu Mar 03, 2005 8:18 am
by feyd
last warning.. read your private messages.

use getimagesize() to determine if the file is the type you want.. The extension means nothing.

Remember to quote named array indices: $extension[extension]