I am trying to modify my code to do the following:

Currently I have to FTP my images to my "Uploads" directory and then use my form to insert the image path into MySQL database.

I want to adjust the code so that it will:

      1.) Send the image path to the database (Does now)
      2.) Move the image to the "Uploads" directory on the server. (need to accomplish)

Any help would be great!

Here is my current code that I need to add to:

 <form method="post" action="<?php echo $PHP_SELF?>">

  <table width="350" border="0" align="center">
  <tr><td width="100" align="left"><b>Choose Category:</b></td><td align="left" width="250"><?php include_once("visitorimagecats.php"); ?></td></tr>
  <tr><td width="100" align="left"><b>Make up a Title:</b></td><td align="left" width="250"><input type="Text" name="title" size="40"></td><tr>
  <tr><td width="100" align="left"><b>Upload image to Database:</b></td><td align="left" width="250"><input type="file" name="image"></td><tr>
  <tr><td width="100" align="left"><b>Submitted by:</b></td><td align="left" width="250"><input type="Text" name="submitted" size="40" value="Anonymous"></td><tr>
  </table>

  <input type="hidden" name="approve" value="2">
  <br>

  <input type="Submit" name="submit" value="Enter Image">

  </form> 

    Since you already have 1 taken care of...

    For 2:

    move_uploaded_file($_FILE['image']['temp_name'], $desired_path . $desired_file_name)
      Installer wrote:

      Since you already have 1 taken care of...

      For 2:

      move_uploaded_file($_FILE['image']['temp_name'], $desired_path . $desired_file_name)

      I'm kinda confused, here is what I've done with the code but it's not right.

      $sql = "INSERT INTO images (category,title,image,submitted,approve) VALUES ('$category','$title','$image','$submitted','$approve')";
        move_uploaded_file($_FILE['image']['temp_name'], $desired_path . $desired_file_name);
      
        $result = mysql_query($sql);
        $desired_path = '/uploads/';
        $desire_file_name = '$image';

      Can you expand on where to place ?

        I had a typo and not a full path, but it still isn't right, but here is what I have at the moment, am I even close ?

        $sql = "INSERT INTO images (category,title,image,submitted,approve) VALUES ('$category','$title','$image','$submitted','$approve')";
        
          $result = mysql_query($sql);
          $desired_path = '/home/blondesa/public_html/uploads';
          $desired_file_name = '$image';
        
          move_uploaded_file($_FILE['image']['temp_name'], $desired_path . $desired_file_name);

          The single quotes around $image cause it to be interpreted literally. To interpret the variable, use double quotes, or better, none at all: $desired_file_name = $image;. And make sure there's a path separator in there ("uploads/"). As long as the upload went ok and $image is defined, it should work. Otherwise see what echo $_FILE['image']['error']; shows.

            Well I tried the changes, but still not working right, at one point it did move 1 temp file to the directory but it then went away and now will not transfer again.

            I tried the " echo $_FILE['image']['error']; " But it shows no error, but I think this is because it is Posting to itself not a different page?

            Here is more of what I have, maybe this will help (sorry for so much script):

            <?php
            if ($submit) {
            
            //Database Connection
               include $_SERVER['DOCUMENT_ROOT'] . '/db.inc.php';
            
              $sql = "INSERT INTO images (category,title,image,submitted,approve) VALUES ('$category','$title','$image','$submitted','$approve')";
            
              $result = mysql_query($sql);
              $desired_path = '/home/blondesa/public_html/uploads/';
              $desired_file_name = $image;
            
              move_uploaded_file($_FILE['image']['temp_name'], $desired_path . $desired_file_name);
            
                echo "<br><br><h1>Thank you for your image!</h1> We will make sure your joke is not obscene or in any way against our terms prior to being approved.<br><br>  <a href='http://www.blondesandrednecks.com/index.php'>Continue</a>
            &nbsp;&nbsp;|&nbsp;&nbsp;<a href='http://www.blondesandrednecks.com/visitorimage.php'>Enter another image</a><br><br>";
            
            } else{
            
              // display form
            
              ?>
            
              <center><table width="100%" border="0">
              <tr><td valign="top">
            
              <form method="post" action="<?php echo $PHP_SELF?>">
            
              <table width="350" border="0" align="center">
              <tr><td width="100" align="left"><b>Choose Category:</b></td><td align="left" width="250"><?php include_once("visitorimagecats.php"); ?></td></tr>
              <tr><td width="100" align="left"><b>Make up a Title:</b></td><td align="left" width="250"><input type="Text" name="title" size="40"></td><tr>
              <tr><td width="100" align="left"><b>Upload image to Database:</b></td><td align="left" width="250"><input type="file" name="image"></td><tr>
              <tr><td width="100" align="left"><b>Submitted by:</b></td><td align="left" width="250"><input type="Text" name="submitted" size="40" value="Anonymous"></td><tr>
              </table>
            
              <input type="Submit" name="submit" value="Enter Image">
            
              </form>
            </td>
            <td valign="top">
            </td></tr>
            </table></center>
            
            <?php
            
            } // end if
            
            ?>

              Edit: Disregard all this, as I see you've started a second thread on the subject.

              First off, I threw you off with a couple of careless typos. It's "$FILES", not "$FILE", and "['tmp_name']", not "['temp_name']". Sorry. (You should read this page to check those, and for valuable information.)

              You're coding as if "register_globals" was turned on, and apparently it is or the "if ($submit)" clause would always fail. That's been deprecated for a long time as there are reasons for not doing it (read this page). So instead of "$submit" use "$POST['submit'], etc. And it looks like you're expecting the upload array ("$FILES") to work the same way, but it doesn't. Even with "register_globals" on, you need to explicitly reference the superglobal array, i.e. "$_FILES['image']['name']" instead of "$image". There's more about this here and here.

              You need to add enctype="multipart/form-data" inside the form path to have any hope of the upload working right

              You can try making those changes (i.e. using the superglobal arrays, etc.) and see what then happens.

              Also, do you have error reporting and display turned on? (Again, apparently you don't or you'd be seeing messages all over your screen.) If not, turn it on.

              I made some changes and got the script to work (I commented out the db stuff):

              //if ($submit) {
                if (isset($_POST['submit'])) { 
              
              //Database Connection 
                 //include $_SERVER['DOCUMENT_ROOT'] . '/db.inc.php'; 
              
                //$sql = "INSERT INTO images (category,title,image,submitted,approve) VALUES ('$category','$title','$image','$submitted','$approve')"; 
              
                //$result = mysql_query($sql); 
                $desired_path = '/home/blondesa/public_html/uploads/'; 
                $desired_file_name = $_FILES['image']['name']; 
              
                move_uploaded_file($_FILES['image']['tmp_name'], $desired_path . $desired_file_name); 
              
                  echo "<br><br><h1>Thank you for your image!</h1> We will make sure your joke is not obscene or in any way against our terms prior to being approved.<br><br>  <a href='http://www.blondesandrednecks.com/index.php'>Continue</a> 
              &nbsp;&nbsp;|&nbsp;&nbsp;<a href='http://www.blondesandrednecks.com/visitorimage.php'>Enter another image</a><br><br>"; 
              } else{ 
              
                // display form 
              
                ?> 
              
                <center><table width="100%" border="0"> 
                <tr><td valign="top"> 
              
                <form enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>"> 
              
                <table width="350" border="0" align="center"> 
                <tr><td width="100" align="left"><b>Choose Category:</b></td><td align="left" width="250"></td></tr> 
                <tr><td width="100" align="left"><b>Make up a Title:</b></td><td align="left" width="250"><input type="Text" name="title" size="40"></td><tr> 
                <tr><td width="100" align="left"><b>Upload image to Database:</b></td><td align="left" width="250"><input type="file" name="image"></td><tr> 
                <tr><td width="100" align="left"><b>Submitted by:</b></td><td align="left" width="250"><input type="Text" name="submitted" size="40" value="Anonymous"></td><tr> 
                </table> 
              
                <input type="Submit" name="submit" value="Enter Image"> 
              
                </form> 
              </td> 
              <td valign="top"> 
              </td></tr> 
              </table></center> 
              
              <?php 
              
              } // end if 

              hth

                Installer thanks for your help, it is appreciated.

                What I have done temporarily is broken this issue into 2 different pages.

                The first page processes all the database information (category, title, image path) to the MySQL database, using
                <form method="post" action="<?php echo $PHP_SELF?>">

                Then I created a link to the second page which will upload the image to the server, using the uploader.php script that you have helped me with, using
                <form enctype="multipart/form-data" action="<?php echo $PHP_SELF?>" method="post">

                And everything works fine. But when I try all the info on one page like I've been trying it sends the image path to the database as a tmp file name NOT as the actual file name.

                I really would like to streamline the process but I think I need to start fresh.

                I will post both pages below if it makes more sense.

                Visitorimage.php (partial page)

                <?php
                if ($submit) {
                
                //Database Connection
                   include $_SERVER['DOCUMENT_ROOT'] . '/db.inc.php';
                
                $sql = "INSERT INTO images (category,title,image,submitted,approve) VALUES ('$category','$title','$image','$submitted','$approve')";
                
                  $result = mysql_query($sql);
                
                
                echo "<br><br><h1>Thank you for your image!</h1> We will make sure your joke is not obscene or in any way against our terms prior to being approved.<br><br>  <a href='http://www.blondesandrednecks.com/index.php'>Continue</a>
                &nbsp;&nbsp;|&nbsp;&nbsp;<a href='http://www.blondesandrednecks.com/uploader.php'>Enter Server image</a><br><br>";
                
                } else{
                
                  // display form
                
                  ?>
                
                
                  <center><table width="100%" border="0">
                  <tr><td valign="top">
                
                  <form method="post" action="<?php echo $PHP_SELF?>">
                
                  <table width="350" border="0" align="center">
                  <tr><td width="100" align="left"><b>Choose Category:</b></td><td align="left" width="250"><?php include_once("visitorimagecats.php"); ?></td></tr>
                  <tr><td width="100" align="left"><b>Make up a Title:</b></td><td align="left" width="250"><input type="Text" name="title" size="40"></td><tr>
                  <tr><td width="100" align="left"><b>Upload image to Database:</b></td><td align="left" width="250"><input type="file" name="image"></td><tr>
                  <tr><td width="100" align="left"><b>Submitted by:</b></td><td align="left" width="250"><input type="Text" name="submitted" size="40" value="Anonymous"></td><tr>
                  </table>
                
                
                  <input type="hidden" name="approve" value="X">
                  <br>
                
                  <input type="Submit" name="submit" value="Enter Image">
                
                  </form>
                </td>
                <td valign="top">
                </td></tr>
                </table></center>
                
                <?php
                
                
                } // end if
                
                ?>

                Uploader.php

                <form enctype="multipart/form-data" action="<?php echo $PHP_SELF?>" method="post">
                
                <table width="350" border="0" align="center">
                <tr><td width="100" align="left"><b>Upload image to Server:</b></td><td align="left" width="250"><input type="file" name="uploadedfile"></td><tr>
                </table>
                
                  <br>
                
                  <input type="Submit" name="submit" value="Enter Image">
                
                  </form>
                
                
                  <?php
                if ($submit) {
                
                // Where the file is going to be placed 
                
                $target_path = "uploads/";
                
                $target_path = $target_path . ( $_FILES['uploadedfile']['name']); 
                
                
                   if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
                    echo "The file ".  ( $_FILES['uploadedfile']['name']). 
                    " has been uploaded <a href='http://www.blondesandrednecks.com/admin'>Administration</a> or <a href='http://www.blondesandrednecks.com/visitorimage.php'>upload another image</a>";
                
                } else{
                
                    echo "There was an error uploading the file, please try again!";
                }
                }
                ?>

                  See if this works:

                  $sql = "INSERT INTO images (category,title,image,submitted,approve) 
                          VALUES ('$category','$title','" . $_FILES['image']['name'] . "','$submitted','$approve')";

                    Thanks Installer, this worked exactly liked I had hoped.

                    Certainly will be a time saver, thanks so much!

                    Installer wrote:

                    See if this works:

                    $sql = "INSERT INTO images (category,title,image,submitted,approve) 
                            VALUES ('$category','$title','" . $_FILES['image']['name'] . "','$submitted','$approve')";
                      Write a Reply...