Current location: Hot Scripts Forums » Programming Languages » PHP » Image File Upload Script


Image File Upload Script

Reply
  #1 (permalink)  
Old 12-28-03, 06:02 PM
Millz Millz is offline
New Member
 
Join Date: Dec 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Image File Upload Script

ok, well ive tried for the last few hours searching through these forums and editing scripts, even wrote me own but still can't get it to work.. this is what i have so far..
::upload.htm::
Code:
<form action="http://www.the-millz.net/images/uploads/upload.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>
::upload.php::
Code:
<?php
$file_types = array( 
'images/uploads/jpg' => 'jpg', 
'images/uploads/gif' => 'gif',
'images/uploads/gif' => 'GIF', 
'images/uploads/png' => 'png',
);
if (!array_key_exists($filetype, $file_types)) { 
echo "Error, not a valid file type"; 
exit;
} 
else
{ 
$file_dir = "http://www.the-millz.net/images/uploads/"; 
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>"; 
} 
} 
}
?>
even though this should upload, restricting the certain files, everytime i just get the same old message, invalid file type.. can anybody help
Reply With Quote
  #2 (permalink)  
Old 12-28-03, 08:52 PM
mdhall's Avatar
mdhall mdhall is offline
Aspiring Coder
 
Join Date: Oct 2003
Posts: 510
Thanks: 1
Thanked 1 Time in 1 Post
$file_types = array(
'image/jpg' => 'jpg',
'image/gif' => 'gif',
'image/gif' => 'GIF',
'image/png' => 'png',
);
Reply With Quote
  #3 (permalink)  
Old 12-28-03, 09:14 PM
nakulgoyal nakulgoyal is offline
Coding Addict
 
Join Date: Jun 2003
Posts: 283
Thanks: 0
Thanked 0 Times in 0 Posts
Re:

I see a plenty of them out there at hotscripts !!
Reply With Quote
  #4 (permalink)  
Old 12-29-03, 05:49 AM
Millz Millz is offline
New Member
 
Join Date: Dec 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
still didnt work lol.. just gettin invalid file types again...
Reply With Quote
  #5 (permalink)  
Old 12-29-03, 03:04 PM
nonsie nonsie is offline
New Member
 
Join Date: Dec 2003
Location: Estonia
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
my 2 cents:
limit it to one file type, jpg for example
if it doesn't work with that, the problem is elsewhere

$ext = strrchr($_FILES['fileupload']['name'], ".");
if($ext = ".jpg")
{
// do stuff
}
Reply With Quote
  #6 (permalink)  
Old 12-30-03, 09:04 AM
snaip's Avatar
snaip snaip is offline
iNET Interactive
 
Join Date: Nov 2003
Posts: 997
Thanks: 2
Thanked 7 Times in 6 Posts
Go through this tutorial:

http://www.edevcafe.com/viewdoc.php?id=46

It should help!
__________________
Regards,
Ahmad Permessur
Team HotScripts
Reply With Quote
  #7 (permalink)  
Old 12-30-03, 10:37 AM
Acecool's Avatar
Acecool Acecool is offline
Aspiring Coder
 
Join Date: Nov 2003
Posts: 506
Thanks: 0
Thanked 0 Times in 0 Posts
Title: Uploading files
Author: Acecool
Description: Shows you how I made my upload files form(s) in the Media Administration area. (Does NOT require globals to be on.)

http://www.acecoolco.com/media_tutorialshow.php?id=36
__________________
Check Acecoolco.com for PHP Tutorials, and other tuts
If you plan on contacting me, please read this: Legal Terms & Conditions
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
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
Basic image upload and data to mysql mdhall Script Requests 3 11-05-03 05:00 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:47 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.