fluidsharp Posted December 24, 2009 Share Posted December 24, 2009 Hello. I'm not understand how to save file from page. I'd like make link to file with save ability. <?php chdir('upload/'); foreach (glob("*.*") as $filename) { $uploadfile = $_GET['file']; readfile ('upload/'.$uploadfile); echo "<a href='upload.php? file=$uploadfile'> $filename </a> </p>"; } ?> and msg appear: Warning: readfile(upload/) [function.readfile]: failed to open stream: No such file or directory in .. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/186293-save-file-by-click/ Share on other sites More sharing options...
.josh Posted December 24, 2009 Share Posted December 24, 2009 echo $uploadfile or view the output source and look at your href. Does it contain what you expect? My guess is you probably want to use $filename instead of that $_GET... Quote Link to comment https://forums.phpfreaks.com/topic/186293-save-file-by-click/#findComment-983826 Share on other sites More sharing options...
fluidsharp Posted December 24, 2009 Author Share Posted December 24, 2009 i've changed: $dir='upload'; echo "<a href= $dir/$filename > $filename </a><br>"; so when I focus cursor on link I see way: http://localhost:8080/upload/Credit.xls, but can't download files from directory (upload). -------------------------- In php man I've found info about force the browser to display the save dialog. There is string: header('Content-Disposition: attachment; filename="downloaded.pdf"'); What about it ? Could you give me some suggestions\way for its task? thanks. Quote Link to comment https://forums.phpfreaks.com/topic/186293-save-file-by-click/#findComment-983842 Share on other sites More sharing options...
fluidsharp Posted December 26, 2009 Author Share Posted December 26, 2009 so... index.php: <?php error_reporting( E_ALL & E_STRICT ); $dir= "upload/"; foreach (glob(/*$dir.*/"*.*") as $file) { echo "<a href='download.php? file=$file'> $file </a> </p>"; } download.php <?php error_reporting( E_ALL & E_STRICT ); $uploadfile = $_GET['file']; if (file_exists($uploadfile)) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename='.basename($uploadfile)); 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($uploadfile)); readfile($uploadfile); } ob_clean(); flush(); exit; header('Location: index.php'); ?> ?> Quote Link to comment https://forums.phpfreaks.com/topic/186293-save-file-by-click/#findComment-984321 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.