?
Solved

copy an image jpg to two locations

Posted on 2010-08-18
5
Medium Priority
?
358 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 40

Accepted Solution

by:
Richard Quadling earned 2000 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 111

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 111

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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

762 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