I have a CDN that is storing media files. Each file I want to store as just the ID number of the file in the data so, file.zip = 4423342 on the server. The problem is, the CDN does not allow php or any form of programming. How can I make it so I have a local file that is used to set the headers and let me change it so when they download a file from the CDN it downloads as file.zip instead of 4423342. Now I know this is simple if the file is stored on the same server as the file that sets the headers.
Thanks!
If your CDN doesn't allow you to set the name/headers of the stored file, you cannot do it on your server. The user gets directed to the CDN server, and you can't "inject" anything into that connection.
I would look into looking up the options your CDN does offer.
For example, you might be able to append something like /file.zip to the end of the CDN url, and still get the correct file.
That is – if the CDN url is http://cdn.example.com/113312, maybe http://cdn.example.com/113312/file.zip works as well.
Related
Is it possible to send file from a local URL?
I need to upload files in php from your local url, eg I open the web page with:
www ... upload.php?url=c://...file.jpg,
from the url GET,I would get the file on the pc and would upload, without using html or anything else that I have to choose, just with the file url.
Important, it can only be this way, it will not be possible to choose the file during the upload, it will only be a POST or GET with the local url.
I researched and found nothing related, if anyone can help
I think it is impossible for server to get a client file by using the file path.
But maybe you can use JS and FileSystemobject to prepare the file, make it to streaming and post to the server.
And you must know FSO need a high security permission and may be disabled on users' browser.
I am trying to download an object/ file from AWS S3 to the local computer. I would like to provide the user with the opportunity to provide the local path. In HTML we have the
<form> and <input type="file">
elements to provide the user with the option to select a file from the file system for upload. How do we do the reverse? Any pointers would be greatly appreciated.
You can't.
Being able to do so would risk websites trying to put stuff in /etc/hosts, ~/.bash_profile, C:\Windows\System32, etc. You can set a (suggested) filename, but it's going to go to the browser's preferred Downloads folder.
It's a security issue to write anywhere you want to the filesystem. You can present it as a download (application/octet-stream / Content-Disposition) but the user's browser gets the right to choose in the end regardless.
You can force a file to download instead of display on a page from the server with a specific filename only, but it stops there. The browser has the choice of popping up a Save As dialog or saving it in the default Downloads folder.
Incidentally, when a user chooses to upload a file, you don't actually get the path either - you get a fake path and a user-defined real filename. On Windows Chrome, it sends something typically like c:\fakepath\ so it doesn't reveal overly-personal information in the path.
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 have a WordPress site, in which type1 users can upload *.doc files and type2 users should be able to open them by clicking on a link which represents a file.
The file then should be opened in a new window of the browser.
I got the first part easily - there are many guides on uploading a file.
But I couldn't find one that goes through all the steps of getting and opening a file which resides on a server directory.
I assume clicking the link should cause an ajax request which will send the file key to the server.
The server can then get from the MySQL DB the file name and location.
But what do I do then?
How do I get the file from the server directory, send it back to the client and open it for reading in the browser?
Edit:
I want the files to be confidential and not let just anyone read them so giving the users the link for the file on the server isn't the right way.
I still think I need to send the file from the server directory to the client.
How can this be done?
You can add links to uploaded media in WordPress easily. Just remember to link to the actual file:
I want the files to be confidential and not let just anyone read them so giving the users the link for the file on the server isn't the right way.
Yes it is. You can't let people read the document without giving them the document.
If you want to keep it confidential, then require the users to agree not to share the link with anyone else. Or go further and add a layer of authentication + authorisation and also require that users not hand over their credentials.
Simply, redirect the browser to the location of the file. It's depend on user's browser settings that file opens on the browser directly, or user sees open/save dialog.
But, if you want to open the file inside the browser without letting user download it, you should redirect her/him to a custom page. e.g. a page that loads a doc editor.
There's no way to show a Microsoft Word file inside the browser unless they install proper software. e.g. an Applet or ActiveX or something that be able to open MSWord files.
Consider using WP Client File Share plugin.
I've got call recordings stored on a CDN (Rackspace CloudFiles) with names like:
KPOWIEJFIE2034020SVN10ASKZALBMRI.mp3
(They're Twilio Call SIDs).
My application (CakePHP) displays a list of these recordings, and uses an <audio> tag to allow them to be played on the page right from the CDN. I need to add the option to download the file directly as well, but I want to download the file named something more like this:
Call from Alex to Firm, Inc, 8/19/2011 4:00pm.mp3
I know how to do this with PHP and readfile() to set the name to whatever I'd like, but that requires the file data be streamed through my VPS. Besides being billed twice for the bandwidth (once through the CDN and once through my VPS), this would defeat the purpose of having my files on a CDN (speed and availability). I have the files named only with the call SID on the CDN for security.
Can I do this with browser-side somehow? Can JavaScript change the name of a downloaded file on the fly?
I appreciate any help!
The filename is based on the URL being requested and the headers attached to the response when the URL is fetched. Unless you proxy it, or can arrange for a "friendly" url to point at the resource, you have no control over how the browser will download the file, since the request will be handled by the rackspace servers, not your code.
JS cannot control the fetch/download process, other than possibly mangling the url that goes into the <audio> tag. but then you're limited to whatever mangling still allows the URL to be relevant to the cloudfiles servers.
You should be able to set an object's Content-Disposition when creating the file. For example,
PUT /<api version>/<account>/<container>/<object> HTTP/1.1
Host: storage.clouddrive.com
X-Auth-Token: 01234567-89ab-cdef-0123-456789abcdef
Content-Type: audio/mpeg
Content-Disposition: attachment; filename=Whatever_Filename_I_Want.mp3
The file will still be stored as whatever your <object> name is, but when retrieved it will appear as Whatever_Filename_I_Want.mp3.
Edit: According to the documentation, you can also update a file's metadata using this method.
From what I understand of the documentation, you're able to build a directory structure on the CDN for your purposes. So instead of relying on the security with the filename, you could put the security into the directory name. That way, http://cdn.example.com/KPOWIEJFIE2034020SVN10ASKZALBMRI.mp3 becomes http://cdn.example.com/KPOWIEJFIE2034020SVN10ASKZALBMRI/Call_from_Alex_to_Firm,_Inc,_8-19-2011_4:00pm.mp3, which will download exactly as you want it to be, without sacrificing the security.