Jump to content


Photo

Re: save img (for redarrow)


  • Please log in to reply
12 replies to this topic

#1 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 09 July 2006 - 12:23 PM

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

}
?>
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#2 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 09 July 2006 - 12:30 PM

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.
<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd

#3 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 09 July 2006 - 12:36 PM

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.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#4 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 09 July 2006 - 12:43 PM

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.

<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd

#5 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 09 July 2006 - 12:46 PM

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

}
?>
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#6 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 09 July 2006 - 12:48 PM

You can look at the FTP functions in PHP and see if those will help you.

Ken

#7 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 09 July 2006 - 12:54 PM

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??
<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd

#8 Koobi

Koobi
  • Staff Alumni
  • Advanced Member
  • 419 posts
  • LocationColombo, Sri Lanka | South Asia

Posted 09 July 2006 - 01:06 PM

i split the topic because the other thread was AV1611's



i dont know if this would download all the 50 images as i am also learning but if someone can tell me cheers.


http://www.phpfreaks....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 :)

#9 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 09 July 2006 - 01:11 PM

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.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#10 Koobi

Koobi
  • Staff Alumni
  • Advanced Member
  • 419 posts
  • LocationColombo, Sri Lanka | South Asia

Posted 09 July 2006 - 01:46 PM

yeah but you should create a seperate thread for that :)

ok to explain your code to you:
<?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);

}
?>



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:
<?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);
}
?>


#11 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 09 July 2006 - 01:49 PM

The for loop was to go throw the array one by one and post 50 images from the database lol.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#12 Koobi

Koobi
  • Staff Alumni
  • Advanced Member
  • 419 posts
  • LocationColombo, Sri Lanka | South Asia

Posted 09 July 2006 - 02:00 PM

The for loop was to go throw the array one by one and post 50 images from the database lol.


but that's what you would use the foreach for

#13 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 09 July 2006 - 02:07 PM

You are the man thank you well done lol..............................
10/10
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users