0

Hello there
have a nice day..
I have PHP script to upload files on servers, I want to copy uploaded files once they uploaded on server to another server using PHP
ex.
upload file F to server A after that copied to server B with same name F.
how to achive this ?

3
Contributors
4
Replies
11
Views
2 Years
Discussion Span
Last Post by diafol
0

am sorry for not being clear :P, I used FTP functions but I need to upload it in background so user don't wait for too long.so if user by mistake refreshed the page, proccess still work in background.
I know there is a way for using "exec" function but I think my server closed this for security reasons.

0

You can also use cUrl to call your own pages without waiting for it to finish. The only problem is that you have to implement something to detect that a file is being handled.

My choice would be to implement a cron job that processes files at regular intervals.

Edited by pritaeas

0

A cron job would be my choice, unless you need this copying to be "immediate". You could of course append a simple files.txt list maybe and reference that from the second site. You don't have to have multiple copies of anything then, you just reference all 'uploaded' files to the first site.
Obviously, you could get even more clever and run a script from the second to the first site - like an API - maybe involving the first site DB.

Many ways see I do.

For example:

Site A:

1) upload file(s) to directory
2) append filename to text file (files.txt)

Site B:

1) get list of files from http://siteA/uploads/files.txt (file_get_contents or cURL)
2) display files with links (href or src attribute) like: 'http://siteA/uploads/' . $filename

So you're not duplicating files all over the place. That's a v. simple solution. You could of course set up an API to retrieve specific, e.g

http://siteA/api?filetype=pdf
http://siteA/api?datefrom=2014-10-10&date_to=2015-01-05
http://siteA/api?username=diafol&filetype=images

But that's for another discussion. Sorry if I went off campus with that.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.