Solved

copy an image jpg to two locations

Posted on 2010-08-18
5
346 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mimic google as my ip 11 53
PHPStorm debugging issues 1 21
mcrypt_create_iv() is deprecated 4 67
Bootstrap collapse causes odd behavior with php loop 7 20
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

919 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

21 Experts available now in Live!

Get 1:1 Help Now