473,386 Members | 1,766 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,386 software developers and data experts.

Moving files by using the function rename()

61
Hi,
I am new to PHP and trying to move a zip file from one directory to another. I researched on the web on this and all fingers pointed to this rename() function.

I tried writing a PHP script which simply moves a zip file (located in the same directory as the source code) to another directory by:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $sourcecode = dirname(__FILE__).'\zipfile.zip'; //appending the current directory with the file name
  3.  
  4. $destination = 'C:\xampp\htdocs';
  5.  
  6. rename($sourcecode, $destination);
  7. ?>
  8.  
I have already tested whether the $sourcecode has the correct path to the file. Upon executing it, my browser gives me this error:

Warning: rename(C:\xampp\htdocs\tutorial\zipfile.zip,C:\xam pp\htdocs) [function.rename]: File exists in C:\xampp\htdocs\tutorial\movingfiles.php on line 5

Any one knows where I am screwing up? Tried to fiddle around with it without much luck.

Thanks for looking at this.
Oct 25 '08 #1
1 5888
Atli
5,058 Expert 4TB
Hi.

The second parameter (the destination) should be a path to a new file, not just the directory you want that file to be in.

In other words:
Expand|Select|Wrap|Line Numbers
  1. $fileName = "file.ext";
  2. $old = "/path/to/old/" . $fileName;
  3. $new = "/path/to/new/" . $fileName;
  4.  
  5. rename($old, $new) or die("Failed to move file");
  6.  
Oct 25 '08 #2

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

Similar topics

7
by: Kamus of Kadizhar | last post by:
Thanks to everyone on this list. I now have a functioning piece of python code!! :-)) Now I'm trying to clean it up. I have the same (or similar) lines repeated several times: ...
16
by: dudufigueiredo | last post by:
I have one folder containing mp3 files, the folder is: C:\My Shared Folder\Rubber Soul And the files are: 01 drive my car.mp3 02 norwegian wood.mp3 03 you won't see me.mp3 04 nowhere man.mp3...
2
by: musicloverlch | last post by:
I need to import 60 text files all in one folder. Can I use VBA to cycle through all the files, without having to import them one by one? Does anyone have an example? Thanks in advance. Laura
5
by: Rothariger | last post by:
Hello.... i want to know if its posible to rename multiple files like windows does.. example: file zzzzzzz.doc file asdasd.doc file esfsefse.doc
11
by: ulyses | last post by:
Let's assume I have following file: 2938929384902491233..... 923949919199191919112.... File contains INTs only. What is more they are huge. For example first row in file may contain integer...
3
by: Daves | last post by:
why the heck can't I use Directory.Move() to rename a directory (containing files) to a entry 2 levels below e.g. uploads/tempfiles -> uploads/tempfiles/48/003files if I do this in one line...
14
by: Realtime | last post by:
Lets say i have a file with the name atest.doc and its in the directory www/directory1 but i want to move that file using php to www/directory2/ how do i do this i tried move_uploaded_file()...
11
by: ABC | last post by:
How to rename files with support wildcard ?
13
by: Avi | last post by:
Hi, Is there a UNIX C system command that will let me copy a file? I am looking for something similar to "cp" that can be called within a C program. I know of the "link" system call but this...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.