PHP redirect and rename file download - php

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.

Related

Download files from portal

Some log files are saved in cloud server and it is placed in another load balancer portal to download it. If I browse the load balancer URL we can see the files to be downloaded. When I click this file its get being downloaded. How this file can be downloaded from Linux commands / php scripts
In Linux terminal using wget command to download file from specific url.
And using php script to download file, you can use file_get_content() and file_put_content() to download file.
I hope this answer helpful to you.

hide download url of files on a download server

I have a php code on one server and a set of files on a download server. the download server is unable to run any php or other types of script. I want to make a download page on php server to download specific files on the download server but hide the file path on the download server. also I have traffic matter so I don't want the php server to get the whole of the file from the download server and make another temporary link for it to download because this make lots of traffic on the php server. how can i resolve this problem? is there any way to use client side safe scripts like js?
You can you the php read function for example:
//specify content type
header('Content-type: application/octet-stream');
readfile('pathtoyourfile')

Save file to server instead of my computer on PHP

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.

Read and write to remote file PHP

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.

PHP Download file from non-hosted directory

I've been able to upload a file through PHP to a non-hosted directory (directory is not on the website) with read/write permissions for the PHP file (www). How would I download the file from this directory? I've been able to list the contents of the directory, but clicking on the files (made the filenames links) does not work as the computer attempts to download the file from the path on the server. I'm new to PHP, so all help is appreciated. Thanks!
Edit: Before I get down votes for this being a broad question, I just want to know how to access the files in the non-hosted directory and pass them to the user. I already know how to download normal files hosted on the website. Thanks!
You can use a delegating PHP file for file access. I don't know anything about your structure, but if you can write it, you can (presumably) read it back with file_get_contents:
<?php
echo file_get_contents('/the/path/to/the/unhosted/directory/file.ext');
?>

Categories