Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Upload one file to 2 different locations

Status
Not open for further replies.

Slimsteve

Technical User
Jun 10, 2003
67
GB
Does anyone know if it is possible to upload a image to different locations on a server at once. I have tried various ways of doing this, but each time the second move_upload does not seem to work, but if I comment out the first move_upload, the second will work, but I cannot do both at the same time. Am I missing something here???

Any help appreciated.

Slim

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"[URL unfurl="true"]http://www.w3.org/TR/html4/loose.dtd">[/URL]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" action="upload.php" method="POST">
    <!-- MAX_FILE_SIZE must precede the file input field -->
    <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
    <!-- Name of input element determines name in $_FILES array -->
<input type="file" name="pictures[]" />
<input type="file" name="pictures[]" />
<input type="submit" value="Send" />
</form>
</body>
</html>

Code:
<?php
foreach ($_FILES["pictures"]["error"] as $key => $error) {
   if ($error == UPLOAD_ERR_OK) {
       $tmp_name = $_FILES["pictures"]["tmp_name"][$key];
       $name = $_FILES["pictures"]["name"][$key];
       move_uploaded_file($tmp_name, "images/$name");
       	move_uploaded_file($tmp_name, "backupimages/$name");

   }
}
?>
 
try this:
Code:
<?php
foreach ($_FILES["pictures"]["error"] as $key => $error) {
   if ($error == UPLOAD_ERR_OK) {
       $tmp_name = $_FILES["pictures"]["tmp_name"][$key];
       $name = $_FILES["pictures"]["name"][$key];
       move_uploaded_file($tmp_name, "images/$name");
   }
}
move_uploaded_file("images/$name", "backupimages/$name");

?>
untested though.

Just a rough guide on how it would be done.

Regards,

Martin

Computing Help And Info:
 

That still produces the same result i.e. I get the images in location one but not it location two.

Slim
 
I'd use
Code:
<?php
foreach ($_FILES["pictures"]["error"] as $key => $error) {
   if ($error == UPLOAD_ERR_OK) {
       $tmp_name = $_FILES["pictures"]["tmp_name"][$key];
       $name = $_FILES["pictures"]["name"][$key];
       if(move_uploaded_file($tmp_name, "images/$name"))
       {
              // we know the move_upload worked, so back it up
              copy("images/$name", "backupimages/$name"); 
       }

   }
}
?>

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top