Adam Kiss Posted December 28, 2011 Share Posted December 28, 2011 Hi boys, I have a little problem here; I have a set of pages–each page has an image (exactly one), which was uploaded some time during last year. Now, since I somehow lost the files that were originally uploaded, I'd like to get all this images into one directory, so I can back it up for other uses. The problem is that I'd like them nicely named and in one directory, and copying/moving files/images in php was always a little black magic for me I'd like to do it this way: open a page with PW script get all the pages in one query for each of these pages, get its image save it into given (ANY on server) directory with '$page->name'.jpg name be happy and download the files. So, if any of you can help me out with the saving part (because everything else is dead simple), I'll be most grateful . Thanks Link to comment Share on other sites More sharing options...
ryan Posted December 29, 2011 Share Posted December 29, 2011 Hey Adam, if I understand correctly, you'll want to do something like this: <?php $pages_with_image = $pages->find("whatever you use to find your pages"); $copy_to_path = '/some/suspicious/dir/'; // including trailing slash foreach($pages_with_image as $p) { $source = $p->image->filename; $target = $copy_to_path . $p->name . "." . $p->image->ext; copy($source, $target); echo "<p>Copied $source => $target</p>"; } Link to comment Share on other sites More sharing options...
Pete Posted December 29, 2011 Share Posted December 29, 2011 Yup - you may well face-palm when you see the copy function ryan posted, but I tend to get confused with this at times too, especially with form input (move_uploaded_file in that case, but you can also use copy in that case as well which confuses me more, even after reading PHP's notes on the move_uploaded_file function). Link to comment Share on other sites More sharing options...
Adam Kiss Posted December 29, 2011 Author Share Posted December 29, 2011 Thank you Ryan, you've just saved me a ton of nerves and time Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now