Jump to content

Re: save img (for redarrow)


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

}
?>
Link to comment
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);

}
?>
Link to comment
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 :)
Link to comment
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]
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.