Solved

copy an image jpg to two locations

Posted on 2010-08-18
5
349 Views
Last Modified: 2012-05-10
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

0
Comment
Question by:rgb192
5 Comments
 
LVL 40

Accepted Solution

by:
Richard Quadling earned 500 total points
ID: 33465677
Take a car. Move it to the garage. Now move it to the shops. You can only "MOVE" it to one place at a time.

Now, let's do something to the image that you can't do to your car.

Copy it.


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

Open in new window

0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 33465752
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!
0
 
LVL 9

Expert Comment

by:Snarfles
ID: 33465764
You can't move something that doesn't exist since its been moved already.

Try php copy instead http://us2.php.net/copy
0
 

Author Closing Comment

by:rgb192
ID: 33465907
thanks
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 33466237
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

0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question