Current location: Hot Scripts Forums » Programming Languages » PHP » image upload, diffrent image formats


image upload, diffrent image formats

Reply
  #1 (permalink)  
Old 07-05-04, 05:04 PM
Andy1984's Avatar
Andy1984 Andy1984 is offline
Newbie Coder
 
Join Date: Jul 2004
Posts: 89
Thanks: 0
Thanked 0 Times in 0 Posts
Question image upload, diffrent image formats

hi guys, i found this neat little script to upload images but being a n00b and proud of it i dunno how to edit the code so i can upload diffrent image formats (jpeg,bmp) aswel as the one its currently set to (gif)

PHP Code:

<form name="form1" method="post" action="" enctype="multipart/form-data"> 

<input type="file" name="imagefile"> 

<input type="submit" name="Submit" value="Submit"> 

<? 
if(isset( $Submit )) 

//If the Submitbutton was pressed do: 

if ($_FILES['imagefile']['type'] == "image/gif"


copy ($_FILES['imagefile']['tmp_name'], "tactic_img/".$_FILES['imagefile']['name']) 
or die (
"Could not copy"); 

echo 
""
echo 
"Name: ".$_FILES['imagefile']['name'].""
echo 
"Size: ".$_FILES['imagefile']['size'].""
echo 
"Type: ".$_FILES['imagefile']['type'].""
echo 
"Copy Done...."


else { 
echo 
""
echo 
"Could Not Copy, Wrong Filetype (".$_FILES['imagefile']['name'].")"



?> </form>
its for part of a tactics page for my clans members area
thanks
-Andy
Reply With Quote
  #2 (permalink)  
Old 07-05-04, 05:36 PM
Bonzo's Avatar
Bonzo Bonzo is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 340
Thanks: 0
Thanked 0 Times in 0 Posts
I cant remember where in the php forum but there is a good example of an upload code for multiple files as well; it has an array defining the file types.

Look at NeverMinds script his as well as others use an array or list that would be easyer to modify I would have thought.

Anthony
Reply With Quote
  #3 (permalink)  
Old 07-05-04, 05:53 PM
kvnband kvnband is offline
Wannabe Coder
 
Join Date: Jun 2003
Posts: 242
Thanks: 0
Thanked 0 Times in 0 Posts
I'm thinking this might do the trick for ya
PHP Code:

<form name="form1" method="post" action="" enctype="multipart/form-data">

<input type="file" name="imagefile">

<input type="submit" name="Submit" value="Submit">

<?
if(isset( $Submit ))
{
//If the Submitbutton was pressed do:

if ($_FILES['imagefile']['type'] == "image/gif" || $_FILES['imagefile']['type'] == "image/jpeg" || $_FILES['imagefile']['type'] == "image/pjpeg" || $_FILES['imagefile']['type'] == "image/bmp")
{

copy ($_FILES['imagefile']['tmp_name'], "tactic_img/".$_FILES['imagefile']['name'])
or die (
"Could not copy");

echo 
"";
echo 
"Name: ".$_FILES['imagefile']['name']."";
echo 
"Size: ".$_FILES['imagefile']['size']."";
echo 
"Type: ".$_FILES['imagefile']['type']."";
echo 
"Copy Done....";
}

else {
echo 
"";
echo 
"Could Not Copy, Wrong Filetype (".$_FILES['imagefile']['name'].")";
}
}

?> </form>
There, I THINK that should work
Reply With Quote
  #4 (permalink)  
Old 07-05-04, 07:17 PM
Andy1984's Avatar
Andy1984 Andy1984 is offline
Newbie Coder
 
Join Date: Jul 2004
Posts: 89
Thanks: 0
Thanked 0 Times in 0 Posts
works perfectly, thanks kvnband

i had first tried that method before i came here after seeing similar code for diffrent formats but i had an error somewhere.

i see where i had gone wrong, thanks again
Reply With Quote
  #5 (permalink)  
Old 07-05-04, 07:43 PM
infinitylimit's Avatar
infinitylimit infinitylimit is offline
Code Guru
 
Join Date: Jun 2004
Location: Oregon
Posts: 758
Thanks: 0
Thanked 0 Times in 0 Posts
I know you are using this on a clan site and probably won't expect hackers but that isn't the securest way to do file uploads. MIME types (ie image/jpeg) are pretty easily faked and you just do a straight copy of whatever is in the temp dir to your dir.

You might consider the following. snagged from http://us2.php.net/features.file-upload
PHP Code:

<?php

// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.

$uploaddir '/var/www/uploads/';
$uploadfile $uploaddir $_FILES['userfile']['name'];

print 
"<pre>";
if (
move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
   print 
"File is valid, and was successfully uploaded. ";
   print 
"Here's some more debugging info:\n";
   
print_r($_FILES);
} else {
   print 
"Possible file upload attack!  Here's some debugging info:\n";
   
print_r($_FILES);
}
print 
"</pre>";

?>
__________________
Hawk Enterprises -- Home to PHP games, open-source code, tutorials and free downloads
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 which copys image name in db marky7890 PHP 1 05-18-04 05:17 PM
will pay. php script needed. upload, resize, & email jamjammo Script Requests 4 02-29-04 08:30 PM
Upload image & text to MYSQL --> AT THE SAME TIME? charliedhq PHP 1 02-20-04 02:57 PM
Basic image upload and data to mysql mdhall Script Requests 3 11-05-03 05:00 PM
Kamk.com Free Image Upload Rbad750 Website Reviews 6 10-18-03 01:43 AM


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