I can now download the file as application/octet-stream but it won't allow me to open the file inline as a PDF. The only way I managed to be able to download the file at all was by stripping the URL from the front of the filename (I think). What am I doing wrong?? $pfile = str_replace('get.php?file=','','$file'); $p = explode('.', $pfile); $extension = $p[sizeof($p)-1];
$pfile when echoed is $file $file when echoed is the correct name of the file which is even more confusing. I figured that $file would include the URL which might be why it hanged explorer. Steve Jackson Web Development and Marketing Manager Viola Systems Ltd. http://www.violasystems.com [EMAIL PROTECTED] Mobile +358 50 343 5159 > -----Original Message----- > From: Steve Jackson [mailto:[EMAIL PROTECTED] > Sent: 17. syyskuuta 2003 13:53 > To: 'PHP General'; 'Jon Haworth' > Subject: RE: [PHP] Getting part of a string...Was protecting > a file via php > > > Thanks to all so far. > However I am still having problems I have directory outside > the root with PDF's in it. The links to the PDF files are > called successfully by this function in a page I call getlinks.php > > function do_non_root_links() > { > define('FILEDIR', '/home/.sites/144/site281/downloads/'); > //display available files > $d = dir(FILEDIR); > while($f = $d->read()) > { > //skip 'hidden' files > if($f{0} != '.') > { > echo "<tr><td>"; > echo "<a href=\"get.php?file=$f\" > class=\"greenlinks\" target=\"_blank\">$f</a>"; > echo "</td></tr>"; > } > } > $d->close(); > } > > The URL displayed is then to be processed by get.php. My problem *I > think* is losing get.php?file= from the URL which I managed > to do by doing $pfile = str_replace('get.php?file=','','$file'); > This however then becomes confusing because $pfile I assumed > would then be simply the filename without the URL. I figured > that if I exploded the name and pulled the extension from the > file passed that into a switch to send the appropriate header > my problem would be solved. However it isn't. This is the > code and de-bugging I've done. <? > define('FILEDIR', '/home/.sites/144/site281/downloads/'); > $path = FILEDIR . $file; > > //check that this file exists and that it doesn't include > //any special characters > if(!is_file($path) OR !eregi('^[A-Z_0-9][A-Z_0-9.]*$', $file)) > { > header("Location: error.php"); > exit(); > } > > /* > ** //check that the user has permission to download file > ** if(user does not have permission) > ** { > ** //redirect to error page > ** header("Location: error.php"); > ** exit(); > ** } > */ > > > $pfile = str_replace('get.php?file=','','$file'); > $p = explode('.', $file); > $extension = $p[sizeof($p)-1]; > // debug - remove the headers and test output vars. > echo "Test and $extension"; > echo "<br>Test and $file"; > echo "<br>Test and $p"; > echo "<br>Test and $pfile"; > /*switch ($extension) > { > // define headers depending on $extension variable. > case "doc" : > header("Content-type: application/msword\n"); > break; > case "pdf" : > header("Content-type: application/pdf\n"); > break; > default : > // force download dialog if no extension defined. > header("Content-type: application/octet-stream\n"); > header("Content-disposition: attachment; filename=\"$file\"\n"); > break; > } > > header("Content-transfer-encoding: binary\n"); > header("Content-length: " . filesize($path) . "\n"); > //send file contents > $fp=fopen($path, "r"); > fpassthru($fp); > */ > ?> > > Echoing the vars produces this. The exploded file > ($extension) is what I need to pass to the switch but if I > send the headers as is again I get a blank and corrupted > explorer window. > > Test and pdf > Test and EventNotification_01.pdf > Test and Array > Test and $file > > Any ideas how to proceed? > Cheers, > > Steve. > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php