Lassie Posted January 17, 2007 Share Posted January 17, 2007 I am trying to finish a download operation and in difficulty.My script is attempting to retieve download locations from a temporary hash directory that contains the product files.I am having difficulty creating1.File path for the download2.Getting the file to open and display a (browser?) alert that would prompt the user to download or save the file.3.My code also needs to account for the fact that the folder may contain multiple files to download.My code is[code]$nogo = 'Sorry, download unavailable. <a href="index.php">Back</a>.'; define('DOWNLOAD_DIR', 'C:/pick_up/'); //open the dir $folder= opendir("C:pick_up/$hash"); // prepare the download //initialise an array to store the contents $files = array(); //loop through the directory while(false !==($item=readdir($folder))) { $files[] = $item; } closedir($folder); if ($files) { foreach ($files as $filename){ echo "The value of $files is $filename";//debug } } $filepath = 'C:/pick_up/$hash/'.$filename;// check that it exists and is readable if (file_exists($filepath) && is_readable($filepath)) {// get the file's size and send the appropriate headers $size = filesize($filepath); header('Content-Type: application/octet-stream'); header('Content-Length: '.$size); header('Content-Disposition: attachment; filename='.$filename); header('Content-Transfer-Encoding: binary');// open the file in binary read-only mode $file = fopen($filepath, 'rb'); if ($file) {// stream the file and exit the script when complete fpassthru($file);exit; }else {echo "$nogo"; } } [/code]I have printed the files array which sows as follows;18da371787b907b8f2506d1e89789f9chash match madeC:/pick_up/18da371787b907b8f2506d1e89789f9cThe value of Array is .The value of Array is ..The value of Array is How to Buy a Car With Little or no credit.pdfArray( [0] => . [1] => .. [2] => How to Buy a Car With Little or no credit.pdf)Any guidance on this is much appreciated.Lassie Quote Link to comment 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.