Jump to content


Simple image upload script that puts image into specified folder?

  • Please log in to reply
4 replies to this topic

#1 Chappers

  • Members
  • PipPipPip
  • Advanced Member
  • 119 posts

Posted 10 July 2006 - 12:52 AM


I want to have an upload facility on a page of my site which lets users upload an image that will be stored in a folder on the server, so I can grab the pic when I want and host it on the page later. I did originally want something that instantly put the image on the page, but then thought better of it knowing the amount of porn pics that'd probably be uploaded just because they can.

I can't use an email form unfortunately, because the free host I'm with has safe mode on, and smtp (send_mail, or something) disabled to stop such things, for spam purposes - but this image upload idea should still be possible, no?

I've just thought, if this is possible, maybe I can get around the problem of not being able to use an email form by having a form that sends the info to a file, which I could then bring up (but not publicly list in the menu) and see all messages sent? I have MySQL available and am using it for a comment form at the moment for adding comments to pages. Only trouble is I have to go into PHPAdmin to delete messages, which I'd have to do with the email type form idea too I s'pose.

Anyway, any ideas welcome.


#2 willfitch

  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts
  • LocationNew Hope, PA

Posted 10 July 2006 - 03:11 AM

Hey Chappers,

I understand your frustration, but asking for someone to write code for you on a forum just isn't right.  Have you tried Googling for a file handling script?  Try http://www.hotscripts.com and see if you can find something there. 

I'm not trying to be mean or rude, but at least give a shot at researching and writing something on your own.  However, if you have problems with coding it, then you should come here and ask questions.

-- Will
Zend Certified Engineer (ZEND001989)

#3 Chappers

  • Members
  • PipPipPip
  • Advanced Member
  • 119 posts

Posted 10 July 2006 - 07:12 PM

Hi, no offense taken; I agree with what you say, and must admit I realised it myself shortly after posting and had planned to delete this topic, but as it was so late, I ended up going to bed. I didn't mean to come across as asking someone to write the code for me, but for some strange reason I had the silly belief that it would be an uncommon request and there wouldn't be such a thing around on the Internet, but that maybe someone had written one themselves and would care to share. I'm not sure why I thought this, because I've taken your advice and found many scripts. Not like me to ask first, Google after, so I apologise.

I'm now going to try adding a few things to the script, such as verifying the file is an image, etc., and adding muliple upload fields so more than one image can be uploaded at a time.

There is one question I have, though: all the scripts I have found upload the image to a directory. As I'd like also to try having a comment form that uploads messages to a file, is there a simple way I can change it from uploading to a directory, to inserting code into a .php file on the server? Or would I have to insert it into a MySQL table, and then use another page to display any messages from there?

Thank you,

#4 bigger_travis

  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 13 February 2007 - 03:53 AM

hi, i found a good tutorial script. i was searching for something like this also. check this code i found in searching google:  LINK hope this helps

#5 redarrow

  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 13 February 2007 - 04:45 AM

class picture
       var $save_dir;                    //where file will be saved
       var $filename="spacer.gif";        //default file name initially 
       var $error_message="";            //string to be output if neccesary
       var $width;                        //height of final image
       var $height;                      //width of final image

       function picture($save_directory, $file_array, $max_width, $max_height)
               $this->save_dir = $save_directory;                
               $this->width =    $max_width;
               $this->height =  $max_height;

               //--change filename to time - make it unique
               $temp_filename = $file_array['name'];
               $ext = explode('.',$temp_filename);
               $ext = $ext[count($ext)-1];
               $temp_filename = time().".".$ext;

               //--check that it's a jpeg or gif
               if (preg_match('/^(gif|jpe?g)$/',$ext)) { 
                       // resize in proportion
                       list($width_orig, $height_orig) = getimagesize($file_array['tmp_name']);
                       if ($this->width && ($width_orig < $height_orig)) {
                               $this->width = ($this->height / $height_orig) * $width_orig;
                       } else {
                               $this->height = ($this->width / $width_orig) * $height_orig;

                       $image_p = imagecreatetruecolor($this->width, $this->height);                        

                       //handle gifs and jpegs separately
                           $image = imagecreatefromgif($file_array['tmp_name']);                            
                           imagecopyresampled($image_p, $image, 0, 0, 0, 0, $this->width, $this->height, $width_orig, $height_orig);
                           imagegif($image_p, $this->save_dir.$temp_filename, 80);
                           $image = imagecreatefromjpeg($file_array['tmp_name']);                            
                           imagecopyresampled($image_p, $image, 0, 0, 0, 0, $this->width, $this->height, $width_orig, $height_orig);                            
                           imagejpeg($image_p, $this->save_dir.$temp_filename, 80);



                       $this->error_message.="<br> file is not a jpeg or gif picture <br>";

Wish i new all about php DAM i will have to learn

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users