Current location: Hot Scripts Forums » Programming Languages » PHP » File Upload Script - Restricting file types ...


File Upload Script - Restricting file types ...

Reply
  #1 (permalink)  
Old 12-27-03, 06:48 AM
Seldimi Seldimi is offline
Newbie Coder
 
Join Date: Sep 2003
Location: Kozani, Greece
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
File Upload Script - Restricting file types ...

HTML Form (uploader.htm)
Code:
<html> 
<head> 
<title> Simple W.M.P. Uploader</title> 
</head> 
<body> 
<form action="uploader.php" enctype="multipart/form-data" method="POST"> 
<input type="hidden" name="MAX_FILE_SIZE" value="51200"> 
File to Upload: <input type="file" name="fileupload"><br><br> 
<input type="submit" value="upload!"> 
</form> 
</body> 
</html>

PHP Script (uploader.php)
PHP Code:

<html> 

<head> 
<title>Simple W.M.P. Uploader</title> 
</head> 
<body> 
<h1>Upload Results</h1> 
<?php 
$file_dir 
"/path/to/upload/directory"

foreach(
$_FILES as $file_name => $file_array) { 
   print 
"path: ".$file_array['tmp_name']."<br>\n"
   print 
"name: ".$file_array['name']."<br>\n"
   print 
"type: ".$file_array['type']."<br>\n"
   print 
"size: ".$file_array['size']."<br>\n"

   if (
is_uploaded_file($file_array['tmp_name'])) { 
      
move_uploaded_file($file_array['tmp_name'], "$file_dir/$file_array[name]") or die ("Failed Transfering"); 
       print 
"Moved !<br><br>"
   } 

?>
Here is a script for uploading ...
How can I restrict the uploading type, like only .gif/.jpg ???

Last edited by Seldimi; 12-27-03 at 06:59 AM.
Reply With Quote
  #2 (permalink)  
Old 12-27-03, 09:39 AM
mdhall's Avatar
mdhall mdhall is offline
Aspiring Coder
 
Join Date: Oct 2003
Posts: 510
Thanks: 1
Thanked 1 Time in 1 Post
<html>
<head>
<title>Simple W.M.P. Uploader</title>
</head>
<body>
<h1>Upload Results</h1>
<?php
$file_types = array(
'image/pjpeg' => 'jpg',
'image/jpeg' => 'jpg',
'image/bmp' => 'bmp',
);
if (!array_key_exists($filetype, $file_types)) {
echo "Error, not a valid file type";
exit;
}
else
{
$file_dir = "/path/to/upload/directory";
foreach($_FILES as $file_name => $file_array) {
print "path: ".$file_array['tmp_name']."<br>\n";
print "name: ".$file_array['name']."<br>\n";
print "type: ".$file_array['type']."<br>\n";
print "size: ".$file_array['size']."<br>\n";
if (is_uploaded_file($file_array['tmp_name'])) {
move_uploaded_file($file_array['tmp_name'], "$file_dir/$file_array[name]") or die ("Failed Transfering");
print "Moved !<br><br>";
}
}
}
?>


Allows only jpg and bmp files to upload, add more to allow other types.




Last edited by mdhall; 12-27-03 at 09:56 AM.
Reply With Quote
  #3 (permalink)  
Old 12-27-03, 09:49 AM
Seldimi Seldimi is offline
Newbie Coder
 
Join Date: Sep 2003
Location: Kozani, Greece
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
Thank you a lot
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there any integrity of script rankings? webmaster@atmanager.com Hot Scripts Forum Questions, Suggestions and Feedback 17 08-06-04 12:12 AM
Upload script having prob with possible upload attack Lexmx PHP 0 12-13-03 10:16 PM
Help with my upload script TheMetsAreBad PHP 2 12-04-03 06:10 PM
ZIP/RAR file comment/.diz/.nfo viewer script net4ward Script Requests 0 11-19-03 04:41 PM
Upload file type and size limiter! Arctic ASP 1 08-02-03 07:06 PM


All times are GMT -5. The time now is 07:44 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.