Re: [PHP] File Open Prompt?

2009-08-29 Thread Ralph Deffke
are u shure, u dont send anything out before u send the headers? even one
space would be too much.

ralph_def...@yahoo.de

Dan Shirah mrsqua...@gmail.com wrote in message
news:a16da1ff0908281328k641ea332v25d887c4de5b3...@mail.gmail.com...
 
  You will need to add some headers to the page to popup the prompt, at
least
  with
  these.
 
  $filename = 'somefile.tif';
  $filesize = filesize($filename);
 
  header('Content-Type: application/force-download');
  header('Content-disposition: attachement; filename=' . $filename);
  header('Content-length: ' . $filesize);
 
  Eric
 
 

 I don't know what I'm doing wrong.  I've tried:

 header('Content-Description: File Transfer');
 header('Content-Type: application/force-download');
 header('Content-Length: ' . filesize($filename));
 header('Content-Disposition: attachment; filename=' . basename($file));
 readfile($file);
 AND

 if (file_exists($new_file)) {
 header('Content-Description: File Transfer');
 header('Content-Type: application/octet-stream');
 header('Content-Disposition: attachment; filename='.basename($new_file
 ));
 header('Content-Transfer-Encoding: binary');
 header('Expires: 0');
 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
 header('Pragma: public');
 header('Content-Length: ' . filesize($new_file));
 ob_clean();
 flush();
 readfile($new_file);
 exit;
 }

 But everything I do just sends heiroglyphics to the screen instead of
giving
 the download box.




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] File Open Prompt?

2009-08-29 Thread Ashley Sheridan
On Sat, 2009-08-29 at 09:03 +0200, Ralph Deffke wrote:
 are u shure, u dont send anything out before u send the headers? even one
 space would be too much.
 
 ralph_def...@yahoo.de
 
 Dan Shirah mrsqua...@gmail.com wrote in message
 news:a16da1ff0908281328k641ea332v25d887c4de5b3...@mail.gmail.com...
  
   You will need to add some headers to the page to popup the prompt, at
 least
   with
   these.
  
   $filename = 'somefile.tif';
   $filesize = filesize($filename);
  
   header('Content-Type: application/force-download');
   header('Content-disposition: attachement; filename=' . $filename);
   header('Content-length: ' . $filesize);
  
   Eric
  
  
 
  I don't know what I'm doing wrong.  I've tried:
 
  header('Content-Description: File Transfer');
  header('Content-Type: application/force-download');
  header('Content-Length: ' . filesize($filename));
  header('Content-Disposition: attachment; filename=' . basename($file));
  readfile($file);
  AND
 
  if (file_exists($new_file)) {
  header('Content-Description: File Transfer');
  header('Content-Type: application/octet-stream');
  header('Content-Disposition: attachment; filename='.basename($new_file
  ));
  header('Content-Transfer-Encoding: binary');
  header('Expires: 0');
  header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  header('Pragma: public');
  header('Content-Length: ' . filesize($new_file));
  ob_clean();
  flush();
  readfile($new_file);
  exit;
  }
 
  But everything I do just sends heiroglyphics to the screen instead of
 giving
  the download box.
 
 
 
 
Try putting all of that inside of a headers_sent(){} block. If nothing
is displayed, it means that you've already sent something to the
browser, so the headers have already been sent and the extra ones you
are sending do nothing. This sort of thing is shown in your error log
also.

If you still get the tif displayed as text, then are you sure that the
tif is valid?

Thanks,
Ash
http://www.ashleysheridan.co.uk




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] File Open Prompt?

2009-08-29 Thread Ralph Deffke
even the .tif is valid or not, the file should be downloaded


Ashley Sheridan a...@ashleysheridan.co.uk wrote in message
news:1251530173.27899.135.ca...@localhost...
 On Sat, 2009-08-29 at 09:03 +0200, Ralph Deffke wrote:
  are u shure, u dont send anything out before u send the headers? even
one
  space would be too much.
 
  ralph_def...@yahoo.de
 
  Dan Shirah mrsqua...@gmail.com wrote in message
  news:a16da1ff0908281328k641ea332v25d887c4de5b3...@mail.gmail.com...
   
You will need to add some headers to the page to popup the prompt,
at
  least
with
these.
   
$filename = 'somefile.tif';
$filesize = filesize($filename);
   
header('Content-Type: application/force-download');
header('Content-disposition: attachement; filename=' . $filename);
header('Content-length: ' . $filesize);
   
Eric
   
   
  
   I don't know what I'm doing wrong.  I've tried:
  
   header('Content-Description: File Transfer');
   header('Content-Type: application/force-download');
   header('Content-Length: ' . filesize($filename));
   header('Content-Disposition: attachment; filename=' .
basename($file));
   readfile($file);
   AND
  
   if (file_exists($new_file)) {
   header('Content-Description: File Transfer');
   header('Content-Type: application/octet-stream');
   header('Content-Disposition: attachment;
filename='.basename($new_file
   ));
   header('Content-Transfer-Encoding: binary');
   header('Expires: 0');
   header('Cache-Control: must-revalidate, post-check=0,
pre-check=0');
   header('Pragma: public');
   header('Content-Length: ' . filesize($new_file));
   ob_clean();
   flush();
   readfile($new_file);
   exit;
   }
  
   But everything I do just sends heiroglyphics to the screen instead of
  giving
   the download box.
  
 
 
 
 Try putting all of that inside of a headers_sent(){} block. If nothing
 is displayed, it means that you've already sent something to the
 browser, so the headers have already been sent and the extra ones you
 are sending do nothing. This sort of thing is shown in your error log
 also.

 If you still get the tif displayed as text, then are you sure that the
 tif is valid?

 Thanks,
 Ash
 http://www.ashleysheridan.co.uk






-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] File Open Prompt?

2009-08-29 Thread Eric

- Original Message - 
From: Ashley Sheridan a...@ashleysheridan.co.uk
To: Ralph Deffke ralph_def...@yahoo.de
Cc: php-general@lists.php.net
Sent: Saturday, August 29, 2009 3:16 PM
Subject: Re: [PHP] File Open Prompt?


 On Sat, 2009-08-29 at 09:03 +0200, Ralph Deffke wrote:
 are u shure, u dont send anything out before u send the headers? even one
 space would be too much.
 
 ralph_def...@yahoo.de
 
 Dan Shirah mrsqua...@gmail.com wrote in message
 news:a16da1ff0908281328k641ea332v25d887c4de5b3...@mail.gmail.com...
  
   You will need to add some headers to the page to popup the prompt, at
 least
   with
   these.
  
   $filename = 'somefile.tif';
   $filesize = filesize($filename);
  
   header('Content-Type: application/force-download');
   header('Content-disposition: attachement; filename=' . $filename);
   header('Content-length: ' . $filesize);
  
   Eric
  
  
 
  I don't know what I'm doing wrong.  I've tried:
 
  header('Content-Description: File Transfer');
  header('Content-Type: application/force-download');
  header('Content-Length: ' . filesize($filename));
  header('Content-Disposition: attachment; filename=' . basename($file));
  readfile($file);
  AND
 
  if (file_exists($new_file)) {
  header('Content-Description: File Transfer');
  header('Content-Type: application/octet-stream');
  header('Content-Disposition: attachment; filename='.basename($new_file
  ));
  header('Content-Transfer-Encoding: binary');
  header('Expires: 0');
  header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  header('Pragma: public');
  header('Content-Length: ' . filesize($new_file));
  ob_clean();
  flush();
  readfile($new_file);
  exit;
  }
 
  But everything I do just sends heiroglyphics to the screen instead of
 giving
  the download box.
 
 
 
 
 Try putting all of that inside of a headers_sent(){} block. If nothing
 is displayed, it means that you've already sent something to the
 browser, so the headers have already been sent and the extra ones you
 are sending do nothing. This sort of thing is shown in your error log
 also.
 
 If you still get the tif displayed as text, then are you sure that the
 tif is valid?


You may also try put these line at top of page to avoid anythings sent before
your attachment headers

error_reporting(E_ALL);
ini_set('display_errors', 1);

Which browsers you used to test it and  their versions ?


- Eric


 Thanks,
 Ash
 http://www.ashleysheridan.co.uk
 
 
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


Re: [PHP] File Open Prompt?

2009-08-29 Thread Eric

- Original Message - 
From: Eric blueray2...@yahoo.com
To: a...@ashleysheridan.co.uk; Ralph Deffke ralph_def...@yahoo.de
Cc: php-general@lists.php.net
Sent: Saturday, August 29, 2009 5:01 PM
Subject: Re: [PHP] File Open Prompt?


 
 - Original Message - 
 From: Ashley Sheridan a...@ashleysheridan.co.uk
 To: Ralph Deffke ralph_def...@yahoo.de
 Cc: php-general@lists.php.net
 Sent: Saturday, August 29, 2009 3:16 PM
 Subject: Re: [PHP] File Open Prompt?
 
 
 On Sat, 2009-08-29 at 09:03 +0200, Ralph Deffke wrote:
 are u shure, u dont send anything out before u send the headers? even one
 space would be too much.
 
 ralph_def...@yahoo.de
 
 Dan Shirah mrsqua...@gmail.com wrote in message
 news:a16da1ff0908281328k641ea332v25d887c4de5b3...@mail.gmail.com...
  
   You will need to add some headers to the page to popup the prompt, at
 least
   with
   these.
  
   $filename = 'somefile.tif';
   $filesize = filesize($filename);
  
   header('Content-Type: application/force-download');
   header('Content-disposition: attachement; filename=' . $filename);
   header('Content-length: ' . $filesize);
  
   Eric
  
  
 
  I don't know what I'm doing wrong.  I've tried:
 
  header('Content-Description: File Transfer');
  header('Content-Type: application/force-download');
  header('Content-Length: ' . filesize($filename));
  header('Content-Disposition: attachment; filename=' . basename($file));
  readfile($file);
  AND
 
  if (file_exists($new_file)) {
  header('Content-Description: File Transfer');
  header('Content-Type: application/octet-stream');
  header('Content-Disposition: attachment; filename='.basename($new_file
  ));
  header('Content-Transfer-Encoding: binary');
  header('Expires: 0');
  header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  header('Pragma: public');
  header('Content-Length: ' . filesize($new_file));
  ob_clean();
  flush();
  readfile($new_file);
  exit;
  }
 
  But everything I do just sends heiroglyphics to the screen instead of
 giving
  the download box.
 
 
 
 
 Try putting all of that inside of a headers_sent(){} block. If nothing
 is displayed, it means that you've already sent something to the
 browser, so the headers have already been sent and the extra ones you
 are sending do nothing. This sort of thing is shown in your error log
 also.
 
 If you still get the tif displayed as text, then are you sure that the
 tif is valid?

 
 You may also try put these line at top of page to avoid anythings sent before
 your attachment headers
 
 error_reporting(E_ALL);
 ini_set('display_errors', 1);
 
 Which browsers you used to test it and  their versions ?
 
 

Also, did you browse it directly or through a secondary page ?
It should used on a second page.

i.e.

page1.php

a href=download.php?id=10download/a

download.php

header( 

-Eric

 
 
 Thanks,
 Ash
 http://www.ashleysheridan.co.uk
 
 
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


[PHP] File Open Prompt?

2009-08-28 Thread Dan Shirah
Greetings,

I'm having a problem trying to get a file download prompt.

Basically I have a page with image links.

When the link is clicked, the user is directed to another page I have. That
page finds the image path based on the image ID from the previous page.

Once the image path is found I copy the image to the local webserver and
rename the proprietary extension, .0D9 to .tif

Once the file is renamed to .tif I want the download prompt to come up.  You
know, where it says, Open Save Cancel.

I've tried using:

$fp = fopen($new_file,r) ;
header(Content-Type: image/tif);
while (! feof($fp)) {
   $buff = fread($fp,filesize($new_file));
   print $buff;
   }

But that just gives me heiroglyphics on the screen instead of prompting the
user to download.

Here is my code that copies and renames the file:

if ($page !=  || $page !=  ) {
 exec(xcopy .$page. .$topage.);
}
$orig_file = $topage.\\.$objectid..0D9;
//echo $orig_file;
$new_file = $topage.\\.$objectid..tif;
//echo $new_file;

rename($orig_file,$new_file);

Any ideas on how to make the browser give the download prompt for $new_file?

Thanks,
Dan


Re: [PHP] File Open Prompt?

2009-08-28 Thread Ashley Sheridan
On Fri, 2009-08-28 at 15:03 -0400, Dan Shirah wrote:

 Greetings,
 
 I'm having a problem trying to get a file download prompt.
 
 Basically I have a page with image links.
 
 When the link is clicked, the user is directed to another page I have. That
 page finds the image path based on the image ID from the previous page.
 
 Once the image path is found I copy the image to the local webserver and
 rename the proprietary extension, .0D9 to .tif
 
 Once the file is renamed to .tif I want the download prompt to come up.  You
 know, where it says, Open Save Cancel.
 
 I've tried using:
 
 $fp = fopen($new_file,r) ;
 header(Content-Type: image/tif);
 while (! feof($fp)) {
$buff = fread($fp,filesize($new_file));
print $buff;
}
 
 But that just gives me heiroglyphics on the screen instead of prompting the
 user to download.
 
 Here is my code that copies and renames the file:
 
 if ($page !=  || $page !=  ) {
  exec(xcopy .$page. .$topage.);
 }
 $orig_file = $topage.\\.$objectid..0D9;
 //echo $orig_file;
 $new_file = $topage.\\.$objectid..tif;
 //echo $new_file;
 
 rename($orig_file,$new_file);
 
 Any ideas on how to make the browser give the download prompt for $new_file?
 
 Thanks,
 Dan

You need to send down the right headers to the browser, so that it knows
it's meant to save the file, and not attempt to display it. If the link
was to a file, you'd have certain header that informed the browser the
mime type of the file.

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] File Open Prompt?

2009-08-28 Thread Andrew Ballard
On Fri, Aug 28, 2009 at 3:03 PM, Dan Shirahmrsqua...@gmail.com wrote:
 Greetings,

 I'm having a problem trying to get a file download prompt.

 Basically I have a page with image links.

 When the link is clicked, the user is directed to another page I have. That
 page finds the image path based on the image ID from the previous page.

 Once the image path is found I copy the image to the local webserver and
 rename the proprietary extension, .0D9 to .tif

 Once the file is renamed to .tif I want the download prompt to come up.  You
 know, where it says, Open Save Cancel.

 I've tried using:

 $fp = fopen($new_file,r) ;
 header(Content-Type: image/tif);
 while (! feof($fp)) {
       $buff = fread($fp,filesize($new_file));
       print $buff;
       }

 But that just gives me heiroglyphics on the screen instead of prompting the
 user to download.

 Here is my code that copies and renames the file:

 if ($page !=  || $page !=  ) {
  exec(xcopy .$page. .$topage.);
 }
 $orig_file = $topage.\\.$objectid..0D9;
 //echo $orig_file;
 $new_file = $topage.\\.$objectid..tif;
 //echo $new_file;

 rename($orig_file,$new_file);

 Any ideas on how to make the browser give the download prompt for $new_file?

 Thanks,
 Dan


You need to send the content-disposition header in addition to the content-type:

header(Content-Disposition: attachment; filename={$clean_file_name};, true);

The filename shouldn't contain spaces or other special characters.
Some browsers will handle it OK if they do, some won't.

There are several lots of posts in the archives that give more details
on how to do it as well as how to avoid some common problems people
have run into.


Andrew

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] File Open Prompt?

2009-08-28 Thread Eric

- Original Message - 
From: Ashley Sheridan a...@ashleysheridan.co.uk
To: Dan Shirah mrsqua...@gmail.com
Cc: PHP General php-general@lists.php.net
Sent: Saturday, August 29, 2009 3:10 AM
Subject: Re: [PHP] File Open Prompt?


 On Fri, 2009-08-28 at 15:03 -0400, Dan Shirah wrote:
 
 Greetings,
 
 I'm having a problem trying to get a file download prompt.
 
 Basically I have a page with image links.
 
 When the link is clicked, the user is directed to another page I have. That
 page finds the image path based on the image ID from the previous page.
 
 Once the image path is found I copy the image to the local webserver and
 rename the proprietary extension, .0D9 to .tif
 
 Once the file is renamed to .tif I want the download prompt to come up.  You
 know, where it says, Open Save Cancel.
 
 I've tried using:
 
 $fp = fopen($new_file,r) ;
 header(Content-Type: image/tif);
 while (! feof($fp)) {
$buff = fread($fp,filesize($new_file));
print $buff;
}
 
 But that just gives me heiroglyphics on the screen instead of prompting the
 user to download.
 
 Here is my code that copies and renames the file:
 
 if ($page !=  || $page !=  ) {
  exec(xcopy .$page. .$topage.);
 }
 $orig_file = $topage.\\.$objectid..0D9;
 //echo $orig_file;
 $new_file = $topage.\\.$objectid..tif;
 //echo $new_file;
 
 rename($orig_file,$new_file);
 


You will need to add some headers to the page to popup the prompt, at least 
with 
these.

$filename = 'somefile.tif';
$filesize = filesize($filename);

header('Content-Type: application/force-download');
header('Content-disposition: attachement; filename=' . $filename);
header('Content-length: ' . $filesize);

Eric

 Any ideas on how to make the browser give the download prompt for $new_file?
 
 Thanks,
 Dan
 
 You need to send down the right headers to the browser, so that it knows
 it's meant to save the file, and not attempt to display it. If the link
 was to a file, you'd have certain header that informed the browser the
 mime type of the file.
 
 Thanks,
 Ash
 http://www.ashleysheridan.co.uk
 
 


Re: [PHP] File Open Prompt?

2009-08-28 Thread Dan Shirah

 You will need to add some headers to the page to popup the prompt, at least
 with
 these.

 $filename = 'somefile.tif';
 $filesize = filesize($filename);

 header('Content-Type: application/force-download');
 header('Content-disposition: attachement; filename=' . $filename);
 header('Content-length: ' . $filesize);

 Eric



I don't know what I'm doing wrong.  I've tried:

header('Content-Description: File Transfer');
header('Content-Type: application/force-download');
header('Content-Length: ' . filesize($filename));
header('Content-Disposition: attachment; filename=' . basename($file));
readfile($file);
AND

if (file_exists($new_file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($new_file
));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($new_file));
ob_clean();
flush();
readfile($new_file);
exit;
}

But everything I do just sends heiroglyphics to the screen instead of giving
the download box.