Solved

copy an image jpg to two locations

Posted on 2010-08-18
5
343 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:
RQuadling 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 108

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 108

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
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 count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now