Jump to content


Upload PHP file code


1 reply to this topic

#1 gilbertsavier

    Young Padawan

  • Members
  • Pip
  • 11 posts

Posted 25 June 2009 - 07:35 AM

I need a code that lets my customers upload a image file from their computer and then that file does 2 things

1. gets uploaded to upload folder on my server
2. a copy of that file gets e-mailed to me

this is what I have so far, any improvements/additions on this code would really be appreciated...

1.//GET IMAGE INFO
2.
3. $dir = 'images/';
4. $file_name = $_FILES['file']['name'];
5. $file_tmp = $_FILES['file']['tmp_name'];
6.
7. //CHECK FOR UPLOADED FILE
8. if(is_uploaded_file($file_tmp)){
9. //MOVE TO DIR
10. move_uploaded_file($file_tmp, $dir.$file_name);
11. }

#2 derek.sullivan

    Jedi In Training

  • Members
  • PipPip
  • 341 posts
  • Gender:Male
  • Location:Georgia
  • Interests:preaching, programming, music, friends, outdoors, moves, books

Posted 26 June 2009 - 10:45 PM

Make sure the directory you want the file to be uploaded to is chmod to 0777, to be writable. Next write your email code ex (may just want to copy/paste):

$to = "youremail@whatever.com";
$subject = "Whatever subject";
$date = date("m/d/Y");
$header = "From: $upload_user"; // change all variables accordingly
$body = "$upload_user has just submited this upload file, http://domain.com/$dir.$file_name";

mail($to, $subject, $body, $header);

add this to your if statement if(is_uploaded_file()) { } hope this helps.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users