Copy file from remote server or URL
While copy()
will accept a URL as the source argument, it may be having issues a url for the destination.
Have you tried specifying the full filesystem path to the output file? I'm assuming you're not trying to put the new file onto a remote server.
For example:
$file = 'http://3.bp.blogspot.com/-AGI4aY2SFaE/Tg8yoG3ijTI/AAAAAAAAA5k/nJB-mDhc8Ds/s400/rizal001.jpg';
$newfile = $_SERVER['DOCUMENT_ROOT'] . '/img/submitted/yoyo.jpg';
if ( copy($file, $newfile) ) {
echo "Copy success!";
}else{
echo "Copy failed.";
}
The above worked nicely for me.
Best way to get a file from remote server and copy to local server using php
Just use copy
$source = "http://www.remotesite.com/video.avi";
$dest = "video.avi";
copy($source, $dest);
PHP - best way to copy remote file to local filesystem
$remote = fopen('http://...', 'r');
$local = fopen('myfile.xml', 'w');
stream_copy_to_stream($remote, $local);
See http://php.net/stream_copy_to_stream. The simpler alternative would actually be to use copy
.
If at all possible, you may want to use rsync instead though, which could make this a whole lot more efficient by transferring only the differences between the two files. I'd set up rsync using a cron job instead of doing this in PHP.
How to copy remote server file in document directory in swift
You can use NSURLSessionDownloadTask to download the file:
func downloadFile(url: URL) {
let downloadRequest = URLRequest(url: url)
URLSession.shared.downloadTask(with: downloadRequest) { location, response, error in
// To do check resoponse before saving
guard let tempLocation = location where error == nil else { return }
let documentDirectory = FileManager.default.urlsForDirectory(.documentDirectory, inDomains: .userDomainMask).last
do {
let fullURL = try documentDirectory?.appendingPathComponent((response?.suggestedFilename!)!)
try FileManager.default.moveItem(at: tempLocation, to: fullURL!)
print("saved at \(fullURL) ")
} catch NSCocoaError.fileReadNoSuchFileError {
print("No such file")
} catch {
// other errors
print("Error downloading file : \(error)")
}
}.resume()
}
let stringURL = "https://wordpress.org/plugins/about/readme.txt"
downloadImage(url: URL(string: stringURL)!)
Update: SWIFT 2.2
func downloadFile(url: NSURL) {
let downloadRequest = NSURLRequest(URL: url)
NSURLSession.sharedSession().downloadTaskWithRequest(downloadRequest){ (location, response, error) in
guard let tempLocation = location where error == nil else { return }
let documentDirectory = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask).first
let fullURL = documentDirectory?.URLByAppendingPathComponent((response?.suggestedFilename)!)
do {
try NSFileManager.defaultManager().moveItemAtURL(tempLocation, toURL: fullURL!)
} catch NSCocoaError.FileReadNoSuchFileError {
print("No such file")
} catch {
print("Error downloading file : \(error)")
}
}.resume()
}
let stringURL = "https://wordpress.org/plugins/about/readme.txt"
let url = NSURL.init(string: stringURL)
downloadFile(url!)
copying a file from a remote server with php copy command
If these are your permissions ls -l /tmp
lrwxr-xr-x@ 1 root wheel 11 Jul 20 23:44 /tmp -> private/tmp – ian 9 hours
That looks like ordinary processes don't have write permission then. The last r-x
means that te other users
(not root
or wheel
group) lack the w
write right. Usually Apache runs under a separate accounts, which is why PHP also cannot access it.
Copy File to remote windows server using .net core
Finally I am able to solve the issue by implementing the Win32 API called WNetUseConnection solutions that was mentioned on below questions:
Accessing a Shared File (UNC) From a Remote, Non-Trusted Domain With Credentials
Related Topics
PHP Float Calculation Error When Subtracting
In PHP How Does Usort() Function Works
Google API Client "Refresh Token Must Be Passed in or Set as Part of Setaccesstoken"
How to Loop Through a Multidimensional Array Without Knowing It's Depth
Premature End of Script Headers: Index.Php, Mod_Fcgid: Read Data Timeout in 61 Seconds
I'm Getting This Error Code: Invalid Argument Supplied for Foreach()
How to Force Doctrine to Update Array Type Fields
How to Get the Last Path in a Url
Laravel - How to Get Current User in Appserviceprovider
How to Set Current Page "Active" in PHP
PHP Soap Client for Uk Mail Webservice API
How to Call a Python Script from PHP
Designing a Secure Auto Login Cookie System in PHP