Current location: Hot Scripts Forums » Programming Languages » PHP » How to name file for download


How to name file for download

Reply
  #1 (permalink)  
Old 07-23-07, 12:56 PM
ELV1I2's Avatar
ELV1I2 ELV1I2 is offline
Newbie Coder
 
Join Date: Jun 2007
Location: BA
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Rolleyes How to name file for download

I know how to read table and make some CSV file that should be ready to download. Contents of file is in variable called $exptekst. I made this in PHP and it's working but I would like to be in position to give a my name that would change each time when download is activated. Now, I know only to "download" always under same name: exported_table.txt.
PHP Code:

header("Content-type: application/x-msdownload");

header("Content-Disposition: attachment; filename=exported_table.txt");
header("Pragma: no-cache");
header("Expires: 0");
print 
"$exptekst"
How to change it? I made also some var like $filename before this part of code and give other name and put code in this way:
PHP Code:

header("Content-type: application/x-msdownload");

header("Content-Disposition: attachment; filename=$filename");
header("Pragma: no-cache");
header("Expires: 0");
print 
"$exptekst"
but then script save CSV file under name of script himself (e.g. downloadit.php)
__________________
There are 3 kind of enemies: my enemies, enemies of my friends and friends of my enemies.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 07-23-07, 02:23 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
That probably means that the variable is not set or empty. Are you sure the variable contains the expected content?

Also, enclosing the name in quotes may work.
PHP Code:

header("Content-Disposition: attachment; filename=\"$filename\""); 

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 07-23-07, 03:30 PM
ELV1I2's Avatar
ELV1I2 ELV1I2 is offline
Newbie Coder
 
Join Date: Jun 2007
Location: BA
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Thumbs up

Quote:
Originally Posted by Nico View Post
That probably means that the variable is not set or empty. Are you sure the variable contains the expected content?

Also, enclosing the name in quotes may work.
PHP Code:

header("Content-Disposition: attachment; filename=\"$filename\""); 

Oh, thank you very much Nico, this part of code was in function that missed $filename as parameter. Also, enclosing the name in quotes helped.
You saved my afternoons and evenings by this suggestion.
__________________
There are 3 kind of enemies: my enemies, enemies of my friends and friends of my enemies.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Upload a file to a fix web folder of a website without using FTP software sujata_ghosh Perl 4 05-10-06 10:10 AM
Checking a file exists lee PHP 3 04-23-06 01:44 AM
Error message not getting displayed. sanjeet Windows .NET Programming 0 12-20-05 11:48 AM
Getting the created file (fopen/fwrite) Programme PHP 5 02-14-04 04:09 PM
Upload file type and size limiter! Arctic ASP 1 08-02-03 08:06 PM


All times are GMT -5. The time now is 10:20 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.