Download and rename file from Server using php script -


I am storing all my files like "8asd98asd9as7d98asd9.file" and the "real" file name is a mysql-database : Retrieving the id from (INt) AI PK, PathOnServer does not tap text, the realfilm name is VARCHAR (200).

I need a script which allows me to access files like "www.website.com/getFile?id=2" which downloads the file and converts it to "actual filename" .

How can this be done?

I believe this code will do a trick for you that you are seeing

  & lt ;? Php if (! Is_numeric ($ _GET ['id'])) {// we validate the parameter echo 'wrong parameter'; Go out(); } $ ODb = new mysqli ("ip", "user", "pass", "database name"); // If connecting to database ($ oDb-> connect_errno) {// check 'error' for an error; Go out(); } $ OResult = $ oDb-> Query ('SELECT' pathOnServer`, `realFilename` FROM --tablename-- WHERE id = '. (Int) $ _GET [' id '].' LIMIT 1 '); // Query ($ oResult-> num_rows! = 1) {echo 'no file found'; Go out(); } $ OQuery = $ oResult-> Fetch_object (); Header ('Content-Attribute: Attachment; File Name ='. $ OQuery-> RealFilename); // Insert special header readfile ($ oQuery-> pathOnServer. $ OQuery-> ID); // put the file? & Gt;   

You can also add headers to the file. Hope this will help you.

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -