Jump to content

Moving files with PHP


denno020

Recommended Posts

Hi all,

 

I would like to move files automatically, using a PHP script, from one folder to another. However each file will go to a different folder, so I want to only move one file at a time, and wait for the previous one to finish before I move on to the next one.

I have some ideas on how I can do this, but I'm not sure how I could test it without actually implementing it and possibly locking up my system if I have too many file transfers happening at once, so I just wanted to bounce them off the knowledgeable people here.

 

The PHP function copy will be able to do the copy for me, and it will return a true/false upon success/failure of the transfer. So I was thinking I could initiate a copy, and then have a while loop that continually loops while the function is false. When it becomes true, it will break the while loop and continue on to the next file.

 

My only concern with this is if the file transfer does actually fail for some reason, then I wouldn't really know..

 

Is there any other way that would be better?

 

I'm going to be using the script to move tv shows from one folder (where they're all mixed up), to its folder on my external hard drive (I can manage figuring out the logic for which folder a file should go to, that's not a problem). Some of the shows can be up to and over 1GB in size too, so I'm not sure if that's something that I would need to take into consideration?

 

Hopefully I've made my problem clear and understandable.

 

Thanks,

Denno

Link to comment
Share on other sites

Firstly, this sounds more like a job for something like rsync, but anyway.

 

Secondly, your logic is completely ass about. You will end up in an infinit loop if a file fails to copy.

 

Thirdly, why are you using copy if you want to move the files? You need to look at rename.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.