I have a url that downloads a .csv file to my computer like this
http://oi62.tinypic.com/2nh0zzt.jpg
The url is
api.infortisa.com/api/Tarifa/GetFile?user=xxxxxxxxxxxxxxxx
But what I want is to download that file in a folder of the server, or at least open it's content so I can save it where i want.
(upload that file via FTP every time is a pain)
I can't access the direct url of the file, just what the api gives me, and that is just a direct download.
I tried curl and file_get_contents, but nothing seems to work.
How can I download that file in the server instead of my computer?
Any help would be appreciated.
Related
I'm trying to archive a big file using PHP and send it to the browser for download. The problem is the file is located on a remote machine and the only way to get it is via HTTP. So imagine this is my file: https://dropboxcontent.com/user333/3yjdsgf/video1.mp4
It's a direct link and I can download the file using wget, or curl anything. When a user wants to download it, I first fetch the file to the server, then zip it up and then send it to the user. Well, if the file is really large, the user has to sit there waiting for the server to download it before he sees the download dialog box in his browser. Is there a way for me to start the download of the file https://dropboxcontent.com/user333/3yjdsgf/video1.mp4 (let's say I'm downloading it into a local /tmp/video.mp4) and simultaneously start putting into an archive and streaming it into the user's browser?
I'm using this library to zip it up: https://github.com/barracudanetworks/ArchiveStream-php, which works great, but the bottleneck is still fetching the file to the server's local filesystem.
Here is my code:
$f = file_get_contents("https://dropboxcontent.com/user333/3yjdsgf/video1.mp4");
$zip->add_file('big/hello.mp4', $f);
The problem is line $f = file_get_contents("https://dropboxcontent.com/user333/3yjdsgf/video1.mp4"); takes too long if the file is really big.
As suggested in the comments of the original post by Touch Cat Digital Inc, I found the answer here: https://stackoverflow.com/a/6914986/1927991
A chunked stream of the remote file was the answer. Very clever.
I am currently trying to retrieve a file from an FTP-Server in order to make it accessible for the user to download. ftp_get() writes it to a path on the local machine, yes, but what I want is that it also shows up in the download history and counts as "normal" download from the internet but I didn't figure out how to do this yet. I also tried to link directly to the file in PHP with header("Location: ftp://username:password#ftp.server.com/myfile.file") but this was resulting in the browser showing the files contents (which I didn't want). Did I miss any header-Parameters ? Or is there a completely different way to do this ?
You won't be able to "redirect" a user to a file so he can download it using FTP. This is a HTTP-thing. Browsers provides FTP features and make it look like HTTP but, in fact, those are different stuff.
If this file is only accessible through FTP and it is on a remote server, the only way I can imagine so you cand 'redirect' this download to the user is:
Download the file from the FTP to your application server through FTP in PHP;
Send it to the user using PHP and appropriate file headers, something like this: https://stackoverflow.com/a/7263943/2802720
Hope it helps.
I've got the following situation: I have some files with hashed filename on a cdn. Now I want a php script which redirects to the files (download) and give them another name. Is there a way without using readfile? The problem with readfile is that it doesn't make sense to download the file from cdn to my webserver and then download the file from the webserver to local computer.
If I have a page with url download.php?id=312, which downloads a file from the server, can I somehow find out the absolute path to the file on the server? The filename is 'hidden' since it's downloaded through the file download.php but can the file give a clue where the file was downloaded from or is it completely hidden?
No you can not find that out. That file, might be even generated on the fly, upon http request to url with parameter download.php?id=312 as a response
I am trying to read and write a remote a file to the user's browser through CodeIgniter(FTP Class). That is, I want user to read the file edit the content and save it back.
One way will be
- download the file to my server
- read the file and echo to the user(Browser)
- Save the content of the file to local copy(My server)
- upload the file back to the server
But I don't want to download the file to my server I just want to read and write to remote file
You can write it to the temporary file and after displaying just delete it using unlink() function in the same script. Just call it straight after echoing the content. The file will be present on your server for a really short period of time. FTP is used to upload files, but not for editing them remotely. Any FTP client supporting file edit is actually saving it to the temp folder on your computer and after the edit uploads it back to the server.