Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

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

$
0
0
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";
  }
?>


Viewing all articles
Browse latest Browse all 13329

Trending Articles