Results 1 to 4 of 4
  1. #1
    Join Date
    May 2013
    Posts
    14

    Unanswered: updating a form after using upload.php for file upload.

    I have a php page (called add_ship.php) with a form to populate a database, including a file upload. This works via a separate file upload.php (shown below).

    What I can't get to work is when a file is uploaded successfully, I've created a link to go back to add_ship.php, with the name of the image as a parameter... how do I get this parameter to fill the correct field in the form, and also, if a user has already entered a few fields, THEN selects upload image, surely all the rest of the data is lost - is there a way to not loose what's been entered (so ideally retuning to add_ship.php and just adding the file name into the correct field?)

    Many thanks

    PHP Code:
    <?php
    $allowedExts 
    = array("gif""jpeg""jpg""png");
    $temp explode("."$_FILES["file"]["name"]);
    $extension end($temp);
    if (((
    $_FILES["file"]["type"] == "image/jpeg")
    || (
    $_FILES["file"]["type"] == "image/jpg")
    || (
    $_FILES["file"]["type"] == "image/png"))
    && 
    in_array($extension$allowedExts))
      {
      if (
    $_FILES["file"]["error"] > 0)
        {
        echo 
    "Return Code: " $_FILES["file"]["error"] . "<br>";
        }
      else
        {
        echo 
    "Image succsefuly uploaded. " "<br>" "<br>";
        
    ?>
        <a href="add_ship.php?file_name= <?php echo $_FILES["file"]["name"?>">Click Hereto return to Add Ship page</a>
    <?php


        
    if (file_exists("upload/" $_FILES["file"]["name"]))
          {
          echo 
    $_FILES["file"]["name"] . " already exists. ";
          }
        else
          {
          
    move_uploaded_file($_FILES["file"]["tmp_name"],
          
    "../images/ships/" $_FILES["file"]["name"]);

          }
        }
      }
    else
      {
      echo 
    "Invalid file";
      }
    ?>

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    create a form element
    send the results of that form element to a script |(can be the same one) and pul the values from the request object
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Code:
    <form action="" method="post">
      <input type="text" name="gv" value="<?=$_POST["gv"]?>">
    </form>
    George
    Home | Blog

  4. #4
    Join Date
    Oct 2013
    Posts
    4
    why do you upload the image seperately? you can also do it, when you send your data from the form. so, you don't have to store it's name in a input-field.

    or use ajax.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •