redarrow Posted July 9, 2006 Share Posted July 9, 2006 i dont know if this would download all the 50 images as i am also learning but if someone can tell me cheers.<?php$get_images=explode( " ",'".$images['images']."');//$images['images']; from database of images.$img=foreach($get_images as $download_images);for($i=0; $i <count($download_images); $i++) {$file=$download_images;$file = $_REQUEST['file'];header("Pragma: public");header("Expires: 0");header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Content-Type: application/force-download");header( "Content-Disposition: attachment; filename=".basename($file));header( "Content-Description: File Transfer");@readfile($file);}?> Quote Link to comment https://forums.phpfreaks.com/topic/14094-re-save-img-for-redarrow/ Share on other sites More sharing options...
ShogunWarrior Posted July 9, 2006 Share Posted July 9, 2006 I think the best thing to do is use a to ZIP/TARgz the images and send them as one file together, otherwise you will have to Save 50 different files one by one. Quote Link to comment https://forums.phpfreaks.com/topic/14094-re-save-img-for-redarrow/#findComment-55090 Share on other sites More sharing options...
redarrow Posted July 9, 2006 Author Share Posted July 9, 2006 i agree with you but i wanted to know if the post that i posted would download all pictures from the database with the code i provided as i am learning cheers.cheers. Quote Link to comment https://forums.phpfreaks.com/topic/14094-re-save-img-for-redarrow/#findComment-55093 Share on other sites More sharing options...
ShogunWarrior Posted July 9, 2006 Share Posted July 9, 2006 I don't think it would, I don't really see how the code works but aside from that {I believe} that the browser will only allow one file to be downloaded. Quote Link to comment https://forums.phpfreaks.com/topic/14094-re-save-img-for-redarrow/#findComment-55095 Share on other sites More sharing options...
redarrow Posted July 9, 2006 Author Share Posted July 9, 2006 I wonder if that will do it.<?php// explode the database varable $get_images=explode( " ",'".$images['images']."');//$images['images']; from database of images.//forech the get images to download images$img=foreach($get_images as $download_images);//go throw the download images till endfor($i=0; $i <count($download_images); $i++) {$file=$download_images;$file = $_REQUEST['file'];header("Pragma: public");header("Expires: 0");header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Content-Type: application/force-download");header( "Content-Disposition: attachment; filename=".basename($file));header( "Content-Description: File Transfer");@readfile($file);}?> Quote Link to comment https://forums.phpfreaks.com/topic/14094-re-save-img-for-redarrow/#findComment-55097 Share on other sites More sharing options...
kenrbnsn Posted July 9, 2006 Share Posted July 9, 2006 You can look at the FTP functions in PHP and see if those will help you.Ken Quote Link to comment https://forums.phpfreaks.com/topic/14094-re-save-img-for-redarrow/#findComment-55099 Share on other sites More sharing options...
ShogunWarrior Posted July 9, 2006 Share Posted July 9, 2006 I'm afraid all that your code does is serve up one file, I modified it to scan a directory so that I could test it but you will only be asked to download one file.What's you database structure, is the contents of the files in the database?? Quote Link to comment https://forums.phpfreaks.com/topic/14094-re-save-img-for-redarrow/#findComment-55105 Share on other sites More sharing options...
Koobi Posted July 9, 2006 Share Posted July 9, 2006 i split the topic because the other thread was AV1611's[quote author=redarrow link=topic=99958.msg393915#msg393915 date=1152447782]i dont know if this would download all the 50 images as i am also learning but if someone can tell me cheers.[/quote]http://www.phpfreaks.com/forums/index.php/topic,99916.msg393910.html#msg393910replace your header() and readfile() with my functions.first try it out and if it doesn't work, let us know and we should be able to help you out but please give it a try yourself, first :) Quote Link to comment https://forums.phpfreaks.com/topic/14094-re-save-img-for-redarrow/#findComment-55117 Share on other sites More sharing options...
redarrow Posted July 9, 2006 Author Share Posted July 9, 2006 Your code is perfect and i also new it was this was not my posts i wanted to know if the code that i posted would do what i wanted it to do cheers mate good work. Quote Link to comment https://forums.phpfreaks.com/topic/14094-re-save-img-for-redarrow/#findComment-55119 Share on other sites More sharing options...
Koobi Posted July 9, 2006 Share Posted July 9, 2006 yeah but you should create a seperate thread for that :)ok to explain your code to you:[code=php:0]<?php//seperates the data from the db after every space$get_images=explode( " ",$images['images']."');//$images['images']; from database of images.//foreach iterates through each value that you got from your previous step$img=foreach($get_images as $download_images);//i don't know why you need this...for($i=0; $i <count($download_images); $i++) {$file=$download_images;//this overrides the previous line...which makes no sense because now, the foreach becomes redundant$file = $_REQUEST['file'];//HTTP headers for cachingheader("Pragma: public");header("Expires: 0");header("Cache-Control: must-revalidate, post-check=0, pre-check=0");//this header tells the browser to prompt the user to download the fileheader("Content-Type: application/force-download");//this header specifies the file nameheader( "Content-Disposition: attachment; filename=".basename($file));header( "Content-Description: File Transfer");//this reads the file and outputs it to the buffer which in this case is your browser@readfile($file);}?>[/code]the above code simply reads a file and prompts the user to download it. your syntax seems faulty. because as far as i know, foreach returns nothing since its a language construct but you assign a variable to it. also the quotes around $images['images'] in your explode function is unnecessary...actually you should get a parse error for that...this is how i would rewrite your code:[code=php:0]<?php/*assuming $images['images'] contains something like:http://example.com/image0.png http://example.com/image1.png http://example.com/image2.png*/$get_images=explode(" ", $images['images']);//you can define these headers before the foreach since they will be the same for every downloadheader("Pragma: public");header("Expires: 0");header("Cache-Control: must-revalidate, post-check=0, pre-check=0");header("Content-Type: application/force-download");header( "Content-Description: File Transfer");foreach($get_images as $download_images){ $file=$download_images; header( "Content-Disposition: attachment; filename=".basename($file)); readfile($file);}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14094-re-save-img-for-redarrow/#findComment-55143 Share on other sites More sharing options...
redarrow Posted July 9, 2006 Author Share Posted July 9, 2006 The for loop was to go throw the array one by one and post 50 images from the database lol. Quote Link to comment https://forums.phpfreaks.com/topic/14094-re-save-img-for-redarrow/#findComment-55145 Share on other sites More sharing options...
Koobi Posted July 9, 2006 Share Posted July 9, 2006 [quote author=redarrow link=topic=99958.msg393974#msg393974 date=1152452967]The for loop was to go throw the array one by one and post 50 images from the database lol.[/quote]but that's what you would use the foreach for Quote Link to comment https://forums.phpfreaks.com/topic/14094-re-save-img-for-redarrow/#findComment-55148 Share on other sites More sharing options...
redarrow Posted July 9, 2006 Author Share Posted July 9, 2006 You are the man thank you well done lol..............................10/10 Quote Link to comment https://forums.phpfreaks.com/topic/14094-re-save-img-for-redarrow/#findComment-55151 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.