What I've done is allow visitors to upload pictures of themselves along with a short description of who they are using HTML Forms. The form is then sent to me via email, and I upload it to the website. Now I'm not 100% sure, but I believe that the image that's uploaded must first go through a server side, because it's moved to a folder called "tmp." Therefore, I have a PHP script that moves it to my destination folder, and then renames the file to its original file name.

The issue is, when I receive the emails sent via form, the file's name is still "tmp/2140712.jpg" instead of it's original file name. But because it has already been moved, the file that was once "tmp/2140712.jpg" is now "thisisme.jpg." This was okay for a while, but I've been starting to receive multiple uploads at once, and I can no longer decipher which picture is which.

    Per php manual:

    $_FILES['userfile']['name']

    The original name of the file on the client machine.[/QUOTE]

    Send that value instead.

      Yes I tried that, and the form results changes to

      "C://Documents and Settings//.. etc"

      and the picture doesn't even upload to my server

      Thank you for trying though!

        Fighters;10879630 wrote:

        Yes I tried that, and the form results changes to

        "C://Documents and Settings//.. etc"

        Huh? Tried it on many servers before (including two just now just in case I recently lost my mind). I do not get the client file path before the file name. Even if I did, I could still parse out just the file name.

        Fighters;10879630 wrote:

        and the picture doesn't even upload to my server

        You wanted the original file name in the email. My suggestion had NOTHING to do with how you upload your file.

        Fighters;10879630 wrote:

        Thank you for trying though!

        Why don't you try sticking a print_r($_FILES); at the top of your form handler. Then post the results here.

          Um, sorry! I don't know much about PHP. Here is my PHP Code:

          <?php
          $body = "Habbo Name: $name \n
          Real Name: $realname \n
          Email Address: $email \n
          Age: $age \n
          About Me: $aboutme \n
          Picture: $datafile \n
          ";
          $name = $_POST['name'];
          $realname = $_POST['realname'];
          $email = $_POST['email'];
          $age = $_POST['age'];
          $aboutme = $_POST['aboutme'];
          $uploadedfile = $_POST['uploadedfile'];
          $body .= "IP address : "; 
          $body .= $_SERVER['REMOTE_ADDR']; 
          
          $from = "From: $email\r\n";
          
          $target_path = "uploads/";
          
          $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
          
          if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
              echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
              " has been uploaded";
          } else{
              echo "There was an error uploading the file, please try again!";
          }
          
          
          mail( "example@example.com", "Pixelbook Entry", $body, $from );
          echo "<center><br /><br /><img src='../habbofigs/frontws.png' alt=' '></img><br />Thank you for signing up for Pixelbook!<br>Click <a href='signup.htm'>here</a> to go back.</a>";
          
          ?>
            $uploadedfile = $_POST['uploadedfile'];

            That will give you the "c:\Document..." thingy. But if you change that to the following:

            $uploadedfile = $_FILES['uploadedfile']['name'];

            You'll just get the original file name. UNLESS, this is a two stage form. Is this code your form handler? Judging from your move_uploaded_file statement, it would appear that this is your actual form handler.

            Now, I cannot tell from your code if $uploadedfile is what you are injecting into your email body. I see a variable called $datafile only above. I guess you could try this:

            $body = "Habbo Name: $name \n
            Real Name: $realname \n
            Email Address: $email \n
            Age: $age \n
            About Me: $aboutme \n
            Picture: {$_FILES['uploadedfile']['name']}\n
            ";

            Sorry if I came across as grouchy. As you can see from my signature, I'm pretty adamant about forum etiquette. When you write things in forums like...

            Thank you for trying though!

            ...comes across as, "You're absolutely wrong and you don't have a clue what you are talking about. Next person please!" Now, after thinking this through, I'm sure I interpreted that incorrectly, and maybe that's just me. However, I think that ppl need to be careful and a better response might have been, "I already tried that and it gives me... and now my picture doesn't get uploaded. Here is my code..."

            I know it seems egotistic, but it's just that people helping here are not getting any compensation for helping you. So please try to be careful to not show disrespect (even by mistake.) People will be more apt to help. I'm sorry for taking offense, I know I shouldn't have. Good luck with your code.

              Err not sure what you mean by "two stage" but I will try your suggestions and let you know!

              Hahaha and yeah, I actually redid that last sentence about 20 times, aware of the misunderstandings that can be so easy via the internet. No disrespect was intentional, and I really do appreciate everything you're doing.

              EDIT: Grr, no luck; I hope this information helps!

              Error Message:

              There was an error uploading the file, please try again!

              <?php
              $body = "Habbo Name: $name \n
              Real Name: $realname \n
              Email Address: $email \n
              Age: $age \n
              About Me: $aboutme \n
              Picture: {$_FILES['uploadedfile']['name']}\n 
              ";
              $name = $_POST['name'];
              $realname = $_POST['realname'];
              $email = $_POST['email'];
              $age = $_POST['age'];
              $aboutme = $_POST['aboutme'];
              $uploadedfile = $_FILES['uploadedfile']['name']; 
              $body .= "IP address : "; 
              $body .= $_SERVER['REMOTE_ADDR']; 
              
              $from = "From: $email\r\n";
              
              $target_path = "uploads/";
              
              $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
              
              if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
                  echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
                  " has been uploaded";
              } else{
                  echo "There was an error uploading the file, please try again!";
              }
              
              
              mail( "example@example.com", "Pixelbook Entry", $body, $from );
              echo "<center><br /><br /><img src='../habbofigs/frontws.png' alt=' '></img><br />Thank you for signing up for Pixelbook!<br>Click <a href='signup.htm'>here</a> to go back.</a>";
              
              ?>
              <CENTER>
              <form METHOD="POST" ENCTYPE="multipart/form-data" action='signup.php'>
              <fieldset><legend>Basic Information</legend>
              <label for="name">Habbo Name:</label>
              <input id="name" name="name" size="30" style="border: 1px solid black; color: #00000; background-color: #ffffff; font-size: 10px; font-family:verdana;text-align:left;">
              
              <BR>
              
              <label for="realname">Real Name:</label>
              <input id="realname" name="realname" size="30" style="border: 1px solid black; color: #00000; background-color: #ffffff; font-size: 10px; font-family:verdana;text-align:left;">
              
              <BR>
              
              <label for="email">E-mail Address:</label>
              <input id="email" name="email"  size="30" style="border: 1px solid black; color: #00000; background-color: #ffffff; font-size: 10px; font-family: verdana;text-align:left;">
              
              <BR>
              
              <label for="age">Age:</label>
              <input id="age" name="age"  size="30" style="border: 1px solid black; color: #00000; background-color: #ffffff; font-size: 10px; font-family: verdana;text-align:left;">
              
              </p>
              </fieldset>
              
              <BR><BR>
              
              <fieldset><legend>About Me</legend>
              <p align='left'>Fill this in to describe a little bit about yourself. Remember, do not give out any personal information.</p>
              
              <label for="aboutme">About Me:</label>
              <textarea id="aboutme" name="aboutme" rows="6" cols="35" style="border: 1px solid black; color: #000000; background-color: #ffffff; font-size: 10px; font-family: verdana;"></textarea>
              
              </p></fieldset>
              
              <BR><BR>
              
              <fieldset><legend>Your Picture:</legend>
              <p align='left'>Remember, no profanity.  And please keep your picture below 600x450, it just makes it that much easier for us.</p>
              <br>
              <input type="hidden" name="MAX_FILE_SIZE" value="100000">
              <input name="uploadedfile" type="file" size="40" style="border: 1px solid black; color: #00000; background-color: #ffffff; font-size: 10px; font-family: verdana;text-align:left;"><br>
              
              <br>
              <p>
              <center><input name="submit" value="Submit" type="submit" class="input_btn" style="width: 24%;"></center></p></fieldset>
                </form></CENTER>
                Err not sure what you mean by "two stage" but I will try your suggestions and let you know!

                Yeah, sorry, I did not explain that well (at all!) It's not even called a "two-stager" or anything either. I know some ppl will code a "wizard-style" set of form handlers. ie. Insert the values of the inputs from the previous form into the form handler as hidden fields, which then get passed to a subsequent form handler.

                It appears that move_upload_file() is failing due to the fact that you get your error message. My bet is on the file path for $target_path, but it could be a few other things:

                1. The file you are trying to upload exceeds 100000 bytes (per your hidden form field)

                2. Your file to upload exceeds the php memory limit (on a separate page look at the output of phpinfo() and look at memory_limit.)

                3. The target path is not right relative to the form handler location. (Try an absolute path: use $_SERVER['DOCUMENT_ROOT'])

                4. File permissions fail (web server user account cannot write to uploads folder)

                We can know precisely if you add the following to your code:

                if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
                echo "The file ". basename( $_FILES['uploadedfile']['name']).
                " has been uploaded";
                } else{
                echo "There was an error uploading the file, please try again! Error: " . $_FILES['uploadedfile']['error'];
                }

                Then reference the error code on this page of the manual.

                  DOH! I feel like an idiot, the issue was a max_file_size. The script is working like a charm now, thank you very much bretticus!

                    Write a Reply...