Solved

download file with a different name.. how ?

Posted on 2009-04-12
2
229 Views
Last Modified: 2013-12-12
hi all thank you for your help in advance
well, i have made  a code which the user  can upload a file and  the script changes the file name into a random number plus some thing like date and time to prevent repeation in the server , so  the file name comes something like this :
4778632-11042009-105236.pdf

the problem is that when the user comes to download the file he downloads it with the same long name, Can any one help how to make a default name that i can set to make people download the file without the real name on the server.

regards
0
Comment
Question by:eCamel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 3

Accepted Solution

by:
iserko earned 500 total points
ID: 24127184
You will need to serve the files using PHP.

I presume you save the original filenames in a database? If so, its only a matter of reading the original filename from the database, reading the file from the disk and serving it.

Example:


<?php
 
// Get original filename from dB
$orig_filename = get_orig_filename_from_db();
// Get the path to the actual file
$path_to_file = get_path_from_db();
 
 
// If this part doesn't work, use the alternative
// =================
$finfo = finfo_open(FILEINFO_MIME, "/usr/share/misc/magic"); // This path depends on your distribution
if (!$finfo) {
    echo "Opening fileinfo database failed";
    exit();
}
$file_mimetype = finfo_file($finfo, $path_to_file);
// =================
// == Alternative ==
// $file_mimetype = mime_content_type($path_to_file);
// =================
 
header('Content-Description: File Transfer');
header('Content-Type: ' . $file_mimetype);
header('Content-Length: ' . filesize($path_to_file));
 
?>

Open in new window

0
 
LVL 3

Assisted Solution

by:iserko
iserko earned 500 total points
ID: 24127189
Forgot about this (add it after content-length):
header('Content-Disposition: attachment; filename=' . $orig_filename);

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question