Need help with an upload PHP code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
groogruxking40
Forum Newbie
Posts: 17
Joined: Wed Jun 17, 2009 8:04 am

Need help with an upload PHP code

Post by groogruxking40 »

I'm running Wordpress 2.8

I would like a script that lets the customer upload a file (jpg,png,gif,etc) pretty much an image file.
Then I would like that file to

(a) be uploaded to my server
(b) a copy sent via e-mail to me

any help?? I know there are some geniuses out there!
dankolle
Forum Newbie
Posts: 3
Joined: Wed Jun 17, 2009 9:07 am

Re: Need help with an upload PHP code

Post by dankolle »

Code: Select all

//GET IMAGE INFO
 
    $dir = 'images/';
    $file_name = $_FILES['file']['name'];
    $file_tmp = $_FILES['file']['tmp_name'];
    
    //CHECK FOR UPLOADED FILE
    if(is_uploaded_file($file_tmp)){
        //MOVE TO DIR
        move_uploaded_file($file_tmp, $dir.$file_name);
             }
 
That should upload the file for you, then just change the directory to the image directory and make sure the permissions are 777 on the folder. Then just use your URL to send the image to you
groogruxking40
Forum Newbie
Posts: 17
Joined: Wed Jun 17, 2009 8:04 am

Re: Need help with an upload PHP code

Post by groogruxking40 »

Thank you so much!!
haven't tried it yet,but I will

now do I just attached a mailto command at the end for it to shoot to my e-mail or what?

Thanks again 8)
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Need help with an upload PHP code

Post by McInfo »

You can send yourself an HTML mail that includes an <img> tag whose src attribute points to a PHP script that returns the image. Or you can embed the image in the email with base-64 encoding. The first method reduces the size of your emails. Look around on this forum for some examples of both of these methods.

Use the mail() function to actually send the email.

PHP Manual: mail

Edit: This post was recovered from search engine cache.
Last edited by McInfo on Tue Jun 15, 2010 11:25 pm, edited 1 time in total.
groogruxking40
Forum Newbie
Posts: 17
Joined: Wed Jun 17, 2009 8:04 am

Re: Need help with an upload PHP code

Post by groogruxking40 »

Ok I got all of that, now do I just upload the .php to my server? or do I actually copy/paste the code on the page I want the form/image upload?
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Need help with an upload PHP code

Post by McInfo »

What ".php" are you referring to? Can you elaborate on what you mean by "copy/paste the code on the page I want the form/image upload"?

Edit: This post was recovered from search engine cache.
Post Reply