Link to home
Start Free TrialLog in
Avatar of rgb192
rgb192Flag for United States of America

asked on

copy an image jpg to two locations

I want to copy the image to two locations


both lines move the file  but willl only let me move once
move_uploaded_file($temp,$uploadedfile);
move_uploaded_file($temp,"newlocation/".$uploadedfile);
move_uploaded_file($uploadedfile,"newlocation/".$uploadedfile);


//move_uploaded_file($temp,$uploadedfile);
move_uploaded_file($temp,"newlocation/".$uploadedfile);
$name= $_FILES["myfile"]["name"];
$temp= $_FILES["myfile"]["tmp_name"]; 
$uploadedfile=$name;
move_uploaded_file($temp,$uploadedfile);
move_uploaded_file($temp,"newlocation/".$uploadedfile);

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Richard Quadling
Richard Quadling
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Please read the man page here:
http://us2.php.net/manual/en/function.move-uploaded-file.php

You need to test the results of this function to see if it worked!
You can't move something that doesn't exist since its been moved already.

Try php copy instead http://us2.php.net/copy
Avatar of rgb192

ASKER

thanks
I posted this to PHP.net.  I guess there is always something new under the sun ;-)
<?php // RAY_temp_upload_example.php
error_reporting(E_ALL);
echo "<pre>" . PHP_EOL;

// IF A FILE HAS BEEN UPLOADED
if (!empty($_FILES))
{
    // SHOW THE UPLOADED FILES
    print_r($_FILES);

    // TRY TO MOVE THE FILE TWICE - SECOND MOVE RETURNS FALSE
    if (!move_uploaded_file($_FILES["userfile"]["tmp_name"], $_FILES["userfile"]["name"])) echo "CANNOT MOVE {$_FILES["userfile"]["name"]}" . PHP_EOL;
    if (!move_uploaded_file($_FILES["userfile"]["tmp_name"], $_FILES["userfile"]["name"])) echo "CANNOT MOVE {$_FILES["userfile"]["name"]}" . PHP_EOL;

    // SHOW THE UPLOADED FILES AFTER THE MOVE - NO VISIBLE CHANGE
    print_r($_FILES);
}

// END OF PHP, PUT UP THE HTML FORM TO GET THE FILE
?>
<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" method="POST">
    <!-- MAX_FILE_SIZE must precede the file input field -->
    <input type="hidden" name="MAX_FILE_SIZE" value="300000" />
    <!-- Name of input element determines name in $_FILES array -->
    Send this file: <input name="userfile" type="file" />
    <input type="submit" value="Send File" />
</form>

Open in new window