My Set-Up:

When a user uploads a file, it first gets uploaded to a folder on my local server, and then gets moved to an amazon s3 server for storage. Currently, when the file is moved to s3, the local file gets deleted.

What I would like to do:

Rather than delete the local file, I would like to replace the local file with a 0-byte file. Reason: so that if another user uploads a file with the same name, the system will know it needs to rename the second file.

My Question:

How can I replace a file ("myvideo.flv") with an empty file of the same name, so that "myvideo.flv" now contains 0 bytes?

1 Answer 1


To replace a file with a zero byte file use a combination of unlink() and touch():


To move a file to a different folder use Drupal's file_move():

file_move($src_file_path, $dest_file_path);

To rename a file use rename():


All of the above make the assumption that your webserver user has read access over the source path, and write access to the destination path.


Your original question asked about moving/renaming files as well, I'll leave the answer to those in just in case you're still wondering.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.