manlio Posted January 29, 2017 Share Posted January 29, 2017 Sorry for the dumb question, but I'm importing some external files into a file field using something like this (it is simplified and $fileurl is changing for every item) foreach ($items as $item) { $item->scheda_tecnica = $fileurl; $item->save(); } The script works perfectly but when there is a missing or wrong URL the script stops. I would like to complete the task and echoing the item that caused the problem. How can I manage this kind of error? Thank you! Link to comment Share on other sites More sharing options...
Robin S Posted January 29, 2017 Share Posted January 29, 2017 You can do this: $failed_files = array(); foreach($items as $item) { if(file_exists($fileurl)) { $item->scheda_tecnica = $fileurl; $item->save(); } else { $failed_files[] = $fileurl; } } // when finished, echo/log the contents of $failed_files 3 Link to comment Share on other sites More sharing options...
adrian Posted January 29, 2017 Share Posted January 29, 2017 Or if it's a remote URL you might need something like this instead of file_exists. $file_headers = @get_headers($filename); if($file_headers[0] == 'HTTP/1.0 404 Not Found') { 3 Link to comment Share on other sites More sharing options...
manlio Posted January 29, 2017 Author Share Posted January 29, 2017 Wow guys you're awesome! My file are online. I will try tomorrow morning. Thank you!! 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