How to upload a file using a form

Collapse
This topic is closed.
X
This is a sticky topic.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • ekeeler
    Corporal

    • Aug 2006
    • 14

    #31
    Re: How to upload a file using a form

    Great, thanks. It all works fine now. Even my stepson can do it!
    Elaine
    Elaine K Keeler

    Comment

    • clanffa
      First Lieutenant

      • Nov 2006
      • 179

      #32
      Re: How to upload a file using a form

      I have a problem with this.
      My website is http://www.ffaproam.com/
      And the upload page is http://www.ffaproam.com/uploadform.php
      My problem is, when someone fills out the info and clicks submit it works fine but the file doesnt get uploaded or anything. I have used BlueFTP and made a file in public_html called uploads. I made its permision777. I added the php script in notepad, editied it, and put that into public_html using BlueFTP. Also, when I get the e-mail after someoen fills out the upload form, it has their video name, e-mail, but where the upload link is it looks like this basicly:
      Video Name:Test
      E-mail:Jackshinta@ffaproam.com
      upload:

      Upload is blank
      Clan FFA-Halo 2 MLG, Machinima, and Glitch Clan
      http://www.ffaproam.com/

      Comment

      • navaldesign
        General & Forum Moderator

        • Oct 2005
        • 12080

        #33
        Re: How to upload a file using a form

        Please look at the other thread you have posted. And post here the php script code.
        Navaldesign
        Logger Lite: Low Cost, Customizable, multifeatured Login script
        Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
        DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
        Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

        Comment

        • clanffa
          First Lieutenant

          • Nov 2006
          • 179

          #34
          Re: How to upload a file using a form

          <?php

          // Receiving variables

          @$email = addslashes($_POST['email']);
          @$upload_Name = $_FILES['upload']['name'];
          @$upload_Size = $_FILES['upload']['size'];
          @$upload_Temp = $_FILES['upload']['tmp_name'];


          // Validation for max file size

          if ($upload_Size>0)
          {
          if( $upload_Size >200000000)
          {
          //delete file
          unlink($upload_Temp);
          header("Location: error.html");
          exit;
          }
          $uploadFile = "uploads/".$upload_Name ;

          @move_uploaded_file( $upload_Temp , $uploadFile);
          chmod($uploadFile, 0644);
          $upload_URL = "http://www.ffaproam.com/uploads/".$upload_Name ;
          }

          //Sending Email to form owner

          $mailto = "jackshinta@ffaproam.com";
          $mailsubj = "Video Upload";
          $mailhead = "From: $email\n";
          reset ($HTTP_POST_VARS);
          $mailbody = "Video Upload Details :\n";
          while (list ($key, $val) = each ($HTTP_POST_VARS))
          {
          if ($key!="submit")
          {
          $mailbody .= "$key : $val\n";
          }
          }
          $mailbody .= "upload: $upload_URL\n";
          mail($mailto, $mailsubj, $mailbody, $mailhead);

          header("Location: thankyou_page.html");

          ?>
          OK Here's that php script you have asked for!
          Clan FFA-Halo 2 MLG, Machinima, and Glitch Clan
          http://www.ffaproam.com/

          Comment

          • navaldesign
            General & Forum Moderator

            • Oct 2005
            • 12080

            #35
            Re: How to upload a file using a form

            Ok, your problem is very simple: you have renamed your upload field, in the form, in "uploadfile" while in the script is "upload". That is why you don't get a value or actual upload. Rename it back to "upload" and it should work.

            Also, please note that php will not allowyou to upload files bigger than 52 MB (you have set it to 200 MB). Files bigger than 52 MB can only be FTPed
            Navaldesign
            Logger Lite: Low Cost, Customizable, multifeatured Login script
            Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
            DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
            Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

            Comment

            • clanffa
              First Lieutenant

              • Nov 2006
              • 179

              #36
              Re: How to upload a file using a form

              Thank you so much navaldesign!!!!!!!!!!!
              You rock my socks off!!!!!!!!!
              YAY Now My clan Members can upload their montages!!
              THIS IS THE ULTIMATE FORUNTAIN OF KNOWLEDGE!!!
              Clan FFA-Halo 2 MLG, Machinima, and Glitch Clan
              http://www.ffaproam.com/

              Comment

              • navaldesign
                General & Forum Moderator

                • Oct 2005
                • 12080

                #37
                Re: How to upload a file using a form

                Please note that you have published the corrected form as php. Correct the extension back to html and publish again
                Navaldesign
                Logger Lite: Low Cost, Customizable, multifeatured Login script
                Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
                DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
                Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

                Comment

                • clanffa
                  First Lieutenant

                  • Nov 2006
                  • 179

                  #38
                  Re: How to upload a file using a form

                  Another question. Ive set the upload to 200mb max. Is there anyway I can add a gile upload progress bar? maybe one that pops up inot a new window which states how much the progress the file is in uploading and the file name? similiar to useruploads.mythica.org??
                  Clan FFA-Halo 2 MLG, Machinima, and Glitch Clan
                  http://www.ffaproam.com/

                  Comment

                  • clanffa
                    First Lieutenant

                    • Nov 2006
                    • 179

                    #39
                    Re: How to upload a file using a form

                    uhh can anyone please help?
                    Clan FFA-Halo 2 MLG, Machinima, and Glitch Clan
                    http://www.ffaproam.com/

                    Comment

                    • navaldesign
                      General & Forum Moderator

                      • Oct 2005
                      • 12080

                      #40
                      Re: How to upload a file using a form

                      A progress bar requires the use of Javascript and AJAX together with PHP. I have only found one script on the net about this, but seems that the relative download link is no more functioning.
                      Navaldesign
                      Logger Lite: Low Cost, Customizable, multifeatured Login script
                      Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
                      DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
                      Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

                      Comment

                      • mrdaytrade
                        Private

                        • Dec 2006
                        • 2

                        #41
                        How To Prevent Files From Being Overwritten

                        I know in frontpage you can set folder properties so file uploads can not overwrite existing files. If a uploaded did this the form would redirect them to an error page stating to rename the file and try again.

                        I am trying to get away from using frontpage, so I used your code from above to modify my form. I had to combine some of the validation to get it to work... I kept getting an Parse error: parse error, unexpected $ in the last line.

                        However, I'm affraid that some people may have the same file name when uploading photos... Is their something I can add to the script to prevent overwriting and a possible error page telling them how to correct the problem. Or even a number being automaticly added to the file name.

                        Is it possible to send the information to a file on the server too? Thanks for the help in advance. I'll send you a digital music coupon.

                        Here is my form:


                        Code:

                        <?php
                        // Receiving variables
                        @$email = addslashes($_POST['email']);
                        @$upload1_Name = $_FILES['upload1']['name'];
                        @$upload1_Size = $_FILES['upload1']['size'];
                        @$upload1_Temp = $_FILES['upload1']['tmp_name'];
                        @$upload2_Name = $_FILES['upload2']['name'];
                        @$upload2_Size = $_FILES['upload2']['size'];
                        @$upload2_Temp = $_FILES['upload2']['tmp_name'];
                        // Validation for max file size
                        if ($upload1_Size>0)
                        {
                        if( $upload1_Size >1000000)
                        {
                        //delete file
                        unlink($upload1_Temp);
                        header("Location: error.html");
                        exit;
                        }
                        $uploadFile = "uploads/".$upload1_Name ;
                        @move_uploaded_file( $upload1_Temp , $uploadFile);
                        chmod($uploadFile, 0644);
                        $upload1_URL = "<A href="http://www.capitalareaapartments.com/uploads/".$upload1_Name">http://www.capitalareaapartments.com/uploads/".$upload1_Name ;
                        }
                        if ($upload2_Size>0)
                        {
                        if( $upload2_Size >1000000)
                        {
                        //delete file
                        unlink($upload2_Temp);
                        header("Location: error.html");
                        exit;
                        }
                        $uploadFile = "uploads/".$upload2_Name ;
                        @move_uploaded_file( $upload2_Temp , $uploadFile);
                        chmod($uploadFile, 0644);
                        $upload2_URL = "<A href="http://www.capitalareaapartments.com/uploads/".$upload2_Name">http://www.capitalareaapartments.com/uploads/".$upload2_Name ;
                        }
                        //Sending Email to form owner
                        $mailto = "sales@capitalareaapartments.com";
                        $mailsubj = "Ad Listing";
                        $mailhead = "From: $email\n";
                        reset ($HTTP_POST_VARS);
                        $mailbody = "Values submitted from web site form :\n";
                        while (list ($key, $val) = each ($HTTP_POST_VARS))
                        {
                        if ($key!="submit")
                        {
                        $mailbody .= "$key : $val\n";
                        }
                        }
                        $mailbody .= "upload1: $upload1_URL\n";
                        $mailbody .= "upload2: $upload2_URL\n";
                        mail($mailto, $mailsubj, $mailbody, $mailhead);
                        header("Location: orderconfirm.htm");
                        ?>


                        Thank you for the code, it was the only site that explained it perfectly!!!
                        -Tony

                        Comment

                        • navaldesign
                          General & Forum Moderator

                          • Oct 2005
                          • 12080

                          #42
                          Re: How to upload a file using a form

                          Yes, there are scripts that will make an incremental saving. Since this is only a forum for our members, not for programming talk, we do no go so deep in the scripts that we post. Go in php.net and see the upload function parametres, i beleive there are some examples of how to make incremental save.

                          Now, as for your script, it seems correct (apart the part that has been modified by this forum's text editor, pursing links even when it shouldn't)

                          Does the script get to upload the files and send the mail ? or doesn't it ?

                          And yes, you can write the data in a file on your server. I simply never use this method, as i prefer storing all the info in a database. The database approach allows for research features, dynamic resizing of the images, realtime registration of the users, anyminute editing possibilities, payment followup, etc. But this exceeds the tutorial's purposes.
                          Navaldesign
                          Logger Lite: Low Cost, Customizable, multifeatured Login script
                          Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
                          DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
                          Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

                          Comment

                          • mrdaytrade
                            Private

                            • Dec 2006
                            • 2

                            #43
                            Re: How to upload a file using a form

                            Originally posted by navaldesign
                            Now, as for your script, it seems correct (apart the part that has been modified by this forum's text editor, pursing links even when it shouldn't)

                            Does the script get to upload the files and send the mail ? or doesn't it ?

                            And yes, you can write the data in a file on your server. I simply never use this method, as i prefer storing all the info in a database. But this exceeds the tutorial's purposes.


                            Yes, it uploads the file and sends the email containing the links to the photos. I've spent countless hours trying to get a php form to work... got yours to work in 10 minutes. Thanks... I'll take a look at the php site. I didn't even realize you are in Italy!

                            Comment

                            • navaldesign
                              General & Forum Moderator

                              • Oct 2005
                              • 12080

                              #44
                              Re: How to upload a file using a form

                              Have a look at http://it.php.net/manual/en/function...oaded-file.php
                              Navaldesign
                              Logger Lite: Low Cost, Customizable, multifeatured Login script
                              Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
                              DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
                              Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

                              Comment

                              • chris.h
                                Private

                                • Aug 2007
                                • 2

                                #45
                                Re: How to upload a file using a form

                                Originally posted by navaldesign View Post
                                UPLOADING MULTIPLE FILES

                                Ok, here is a script for uploading two files. The same structure can be adopted for multiple files, repeating the blocks as they appear in the script.
                                Please note that this script follows the same logical structure of the single upload field one, but with some additional checking: f.e. the size error checking has to be done for both upload fields BEFORE the script starts uploading. Then it has to check again, field by field, before it starts the real upload, otherwise you could have error headers sent out and the script broken, if f.e. one of the two fields is empty.
                                Please note that this is NOT what i would have used: a would have used a include file to minimise scripting. However, this would exceed the capabilities of the average user, as it would require more php files to be compiled and uploaded. This way instead, it is pretty straight.


                                <?php
                                // Receiving variables
                                @$email = addslashes($_POST['email']);
                                @$upload_Name = $_FILES['upload']['name'];
                                @$upload_Size = $_FILES['upload']['size'];
                                @$upload_Temp = $_FILES['upload']['tmp_name'];
                                @$upload1_Name = $_FILES['upload1']['name'];
                                @$upload1_Size = $_FILES['upload1']['size'];
                                @$upload1_Temp = $_FILES['upload1']['tmp_name'];

                                // Validation for max file size

                                // Validation for the first file, if it exists. Repeat the block as many times as your upload fields.

                                if ($upload_Size>0)
                                {
                                if( $upload_Size >1000000)
                                {
                                //delete file
                                unlink($upload_Temp);
                                header("Location: error.html");
                                exit;
                                }
                                }

                                // Validation for the second file, if it exists. In the additional blocks, change the number 1 to 2 or 3 or ... n

                                if ($upload1_Size>0)
                                {
                                if( $upload1_Size >1000000)
                                {
                                //delete file
                                unlink($upload1_Temp);
                                header("Location: error.html");
                                exit;
                                }
                                }
                                // Uploading the first file, if it exists. Repeat as many times as your upload fields.

                                if ($upload_Size>0)
                                {
                                $uploadFile = "uploads/".$upload_Name ;
                                @move_uploaded_file( $upload_Temp , $uploadFile);
                                chmod($uploadFile, 0644);
                                $upload_URL = "http://www.yourdomain.com/uploads/".$upload_Name ;

                                // Uploading the second file, if it exists.

                                if ($upload1_Size>0)
                                {
                                $uploadFile = "uploads/".$upload1_Name ;
                                @move_uploaded_file( $upload1_Temp , $uploadFile);
                                chmod($uploadFile, 0644);
                                $upload1_URL = "http://www.yourdomain.com/uploads/".$upload1_Name ; // You must change the number 1 to 2 or 3 or whatever in the additional blocks
                                }
                                //Sending Email to form owner
                                $mailto = "youremail@yourdomain.com";
                                $mailsubj = "Enter Your Subject Here";
                                $mailhead = "From: $email\n";
                                reset ($HTTP_POST_VARS);
                                $mailbody = "Values submitted from web site form :\n";
                                while (list ($key, $val) = each ($HTTP_POST_VARS))
                                {
                                if ($key!="submit")
                                {
                                $mailbody .= "$key : $val\n";
                                }
                                }
                                $mailbody .= "File Link 1: $upload_URL\n"; // This line is to add the link to the first file. Repeat as many times as your upload fields
                                $mailbody .= "File Link 2: $upload1_URL\n"; // This line is to add the link to the second file.

                                $mailbody .= "If any link is broken, please copy and paste it in your browser's address bar\n";

                                mail($mailto, $mailsubj, $mailbody, $mailhead);

                                // Autoresponder: if you don't want the autoresponder, delete this and the following 7 lines in Green color



                                if ($Copy != "")
                                {
                                $mailto = $email;
                                $mailsubj = "Copy of the info you Submitted";
                                $mailhead = "From: put your site or company name here: \n";
                                mail($mailto, $mailsubj, $mailbody, $mailhead);
                                }




                                header("Location: thankyou_page.html");

                                ?>

                                As always change the part s in blue to be your own details. The blocks can be repeated as many times as you want, to include as many upload fields as you want. The fields in the form should be named: upload, upload1, upload2, upload3, ...... upload(n) where n is the last field.

                                You can test the form here. If you tick the small bottom check box, you will receive a copy email of the info submitted, with the file kinks, so you can check yourself how the script works.

                                Hi, Having some trouble getting this script to run, the single upload version works fine, however this one fails on the rediret, both on the error redirect and the thank you one.

                                I get the following message:

                                Parse error: syntax error, unexpected $end in /home/gopriva1/public_html/test/uploadaction.php on line 93

                                Yet if I switch back to the single upload version all works fine. Am I missing sometihng?

                                Many thanks
                                Chris

                                Comment

                                Working...
                                X