473,401 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

HOW to upload to two places?

13
this is what i have so far but it uploads to the first location but not second.
Expand|Select|Wrap|Line Numbers
  1. $newname = dirname(__FILE__).'/upload'.$myvar;
  2.       $newcopy = dirname(__FILE__).'/copy'.$today.$myvar;
  3.       //Check if the file with the same name is already exists on the server
  4.       if (!file_exists($newname)) {
  5.         //Attempt to move the uploaded file to it's new place
  6.         if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname))) {
  7.            echo "It's done! The file has been saved as: ".$newname;
  8.         } else {
  9.            echo "Error: A problem occurred during file upload!<br>";
  10.         }
  11.         if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newcopy))) {
  12.            echo "It's done! The file has been saved as: ".$newcopy;
  13.         } else {
  14.            echo "Error: A problem occurred during file upload!";
  15.         }
  16.  
where the second location prints the file name with a date.
thanks in advance.
Dec 1 '10 #1

✓ answered by dlite922

I think you both miss the concept of "move".

Once you move it once, it is no longer there!

You need to COPY the file if you need another 'copy'.


Dan

3 1734
Thew
69
Try this:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3.     $newname = dirname(__FILE__).'/upload'.$myvar;
  4.     $newcopy = dirname(__FILE__).'/copy'.$today.$myvar;
  5.  
  6.  
  7.     if (!file_exists($newname)) {
  8.         if(!file_exists($newcopy)) {
  9.             if (move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname)) 
  10.             {
  11.                 echo 'File 1 has been uploaded...<br/>';
  12.  
  13.                     if (move_uploaded_file ($_FILES['uploaded_file']['tmp_name'],$newcopy))
  14.                     {
  15.                         echo 'File 2 too! Lets party! <br/>';
  16.                     }
  17.                     else
  18.                     {
  19.                         echo 'but file 2 wasn t? <br/>';
  20.                     }
  21.             }
  22.             else
  23.             {
  24.                 'File 1 wasn t uploaded so File 2 neither.<br/>';
  25.             }
  26.         }
  27.         else
  28.         {
  29.             echo 'File 2 already exists! <br/>';
  30.         }
  31.     }
  32.     else
  33.     {
  34.         echo 'File 1 already exists! <br/>';
  35.     }
  36.     ?>
  37.  
What does it display?
Dec 1 '10 #2
dlite922
1,584 Expert 1GB
I think you both miss the concept of "move".

Once you move it once, it is no longer there!

You need to COPY the file if you need another 'copy'.


Dan
Dec 1 '10 #3
MOzgaf
13
Thank you thew the code works fine. I used the copy()function as well dlite922. thanks
Dec 3 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: weiwei | last post by:
Hi All I want to upload either image or word document into either access or SQL server database so far I am doing some small testings and what I can do is upload the file from first page and...
5
by: kbrad | last post by:
I am trying to use SoftArtisans FileUp Professional to upload a directory. I have found some sample code to help but you have to type in the directory name when you run the page. I want to use a...
4
by: Vic Spainhower | last post by:
Hello, I am trying to setup a file upload using the example from the PHP manual. However, I am getting an Undefined index on userfile in the 2 places where it is referenced. Can someone please...
0
by: TonyR | last post by:
Can anyone help? I am writing an application to upload a data file to a remote website running IIS and FP2002 extensions. If I use "My Network Places" in windows XP, I can do this with...
9
by: Wayne Smith | last post by:
I've come up against a major headache that I can't seem to find a solution for but I'm sure there must be a workaround and I would really be grateful of any help. I'm currently building a web...
4
by: abhanjee | last post by:
Hello, I am a newbie and am developing an application for work. I have figured out how to upload a file attachment to the SQL database and download the same file using C# and Visual Studio....
0
by: AccessFreak | last post by:
I'm one of those learn by example folks so be gentle... LOL! Scenario: Website owner chooses .csv to upload via upload.htm. He clicks "Upload File". He is then taken to upload.asp where the .csv...
1
by: =?Utf-8?B?TGFtaXM=?= | last post by:
HI, I am doing an aspx application and need to let my users be able to edit the information in my database by the page. My first Idea was to let them export the information to an excel file at...
16
by: Lawrence Krubner | last post by:
To guard against our users possibly uploading huge files, I've got this in my php.ini file: ; Maximum size of POST data that PHP will accept. post_max_size = 10M On a server running Ubuntu...
8
johngault
by: johngault | last post by:
I've been working with this PHP page for several days now and I'm stumped. The page is supposed to allow the user to upload up to six images for their profile. When the user adds an image it (the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.