h365 Posted March 14, 2018 Share Posted March 14, 2018 Hi guys, so i ran into an issue. I have an Import Script for Products, each product has some images. When i save them to Processwire the Images get uploaded. But when i run the importer again, the images are uploaded again, with filename-1, filename-2 etc.. Is there a way to prevent this.. so if an image already exists within a page i doesnt get uploaded again ? A Possibility would be to add the Source Url of the image as Metadata to the image and then check before uploading if it already exists or something? Help is really appreciated! Thanks Link to comment Share on other sites More sharing options...
monchu Posted March 14, 2018 Share Posted March 14, 2018 you can use count if (!count($page->images)) { // upload images } else { // no upload } Link to comment Share on other sites More sharing options...
h365 Posted March 14, 2018 Author Share Posted March 14, 2018 but that wont check if the image already exists, and if not then upload it otherwise skip it? Cheers Link to comment Share on other sites More sharing options...
Robin S Posted March 14, 2018 Share Posted March 14, 2018 For a page $p with images field "images" and an array of image paths/URLs... $p->of(false); $u = new WireUpload('image_check'); foreach($image_paths as $image_path) { // Get path parts $parts = pathinfo($image_path); // Convert filename to PW format $image_name = $u->validateFilename($parts['basename']); // Look for filename in images field if(!$p->images->get($image_name)) { // Image does not already exist in field, so add it $p->images->add($image_path); } } $p->save(); 3 Link to comment Share on other sites More sharing options...
h365 Posted March 15, 2018 Author Share Posted March 15, 2018 Thanks @Robin S that does the job! Do you know if the Wireupload module is capable of doing batch uploads if i provide multiple Image URLS? Or some kind of queueing? Link to comment Share on other sites More sharing options...
Robin S Posted March 15, 2018 Share Posted March 15, 2018 8 minutes ago, h365 said: Do you know if the Wireupload module is capable of doing batch uploads if i provide multiple Image URLS? Or some kind of queueing? In this situation you aren't using WireUpload directly - rather Pageimages::add(). You can only give this method one image path at a time, but if you call it repeatedly in a loop it will keep uploading the images you give it until it is finished (or until PHP times out - you might want to increase max_execution_time if you have a lot of images to upload). 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