Jump to content

Archived

This topic is now archived and is closed to further replies.

redarrow

Re: save img (for redarrow)

Recommended Posts

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);

}
?>

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 end
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);

}
?>

Share this post


Link to post
Share on other sites
You can look at the FTP functions in PHP and see if those will help you.

Ken

Share this post


Link to post
Share on other sites
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??

Share this post


Link to post
Share on other sites
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#msg393910
replace 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 :)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 caching
header("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 file
header("Content-Type: application/force-download");
//this header specifies the file name
header( "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 download
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-Description: File Transfer");

foreach($get_images as $download_images)
{
    $file=$download_images;
    header( "Content-Disposition: attachment; filename=".basename($file));

    readfile($file);
}
?>
[/code]

Share this post


Link to post
Share on other sites
The for loop was to go throw the array one by one and post 50 images from the database lol.

Share this post


Link to post
Share on other sites
[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

Share this post


Link to post
Share on other sites
You are the man thank you well done lol..............................
10/10

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.