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 ?

Recommended Answers

All 4 Replies

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.

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.

Member Avatar for diafol

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.