Hi,
I'm using phpwebgallery 1.3 with alcz mod for exif data.
As I always use the same pattern to rename my files (e.g. "05_-_Alex_and_Seb.jpg"), I would like the system to fill in the database (_images table) for each picture with :
- "Alex and Seb" as name ;
- the Exif Datetime as creation_date
- "Eric" as author (I've shot almost all my pictures)
So, I've tried to write a piece of code for that. Here it is, inspired by some lines of category.php and picture.php
// this function aims at generate pictures properties thanks to filename // and Exif metadata. // For each picture, it will: // 1) Read the database // 2) Adjust the name of the picture // 3) Read Exit DateTime // 4) Store these information in the database include_once( './include/init.inc.php' ); include_once( './include/functions_exif.inc.php' ); // Retrieve auto_incremement $query = 'SELECT max(id)'; $query.= ' FROM '.PREFIX_TABLE.'images'; $query.= ';'; $result = mysql_query( $query ); while ( $line = mysql_fetch_row( $result ) ) { $id_max = $line[0]; } //print($id_max); for ($id = 1122; $id <= $id_max; $id++) { $array_cat_directories = array(); // Read the properties stored in database $query = 'SELECT file,date_creation,name,comment,author'; $query.= ',storage_category_id'; $query.= ' FROM '.PREFIX_TABLE.'images'; // $query.= ' FROM '.PREFIX_TABLE.'images AS i'; // $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category AS ic ON id=ic.image_id'; // $query.= $page['where']; // $query.= $conf['order_by']; // $query.= ' LIMIT '.$page['start'].','.$page['nb_image_page']; $query.= ' WHERE id = ' .$id; $query.= ';'; $result = mysql_query( $query ); while ( $row = mysql_fetch_array( $result ) ) { // retrieving the storage dir of the picture if ( $array_cat_directories[$row['storage_category_id']] == '' ) { $array_cat_directories[$row['storage_category_id']] = get_complete_dir( $row['storage_category_id'] ); } $cat_directory = $array_cat_directories[$row['storage_category_id']]; $image_link = $cat_directory.$page['file']; $file = get_filename_wo_extension( $row['file'] ); // Adjust the name of the picture by removing the '015 - ' and // replacing the underscores by spaces if ( $row['name'] != '' ) $update_name = 0; else { $name = ereg_replace('^[0-9]_-_', '', $file); $name = str_replace( '_', ' ', $name ); $update_name = 1; } // Copy the name in comment if the filename is too long if( ( $row['comment'] != '' ) or (strlen($name) < 25) ) $update_comment = 0; else $comment = $name; $name = substr($name, 0, 25); $update_comment = 1; } // Read Exif DateTime if ( $row['date_creation'] != '') $update_date = 0; else { $date = exif_data( $image_link, array('DateTime'), $lang ); $update_date = 1; } $id = $row['id']; // Update database to store the previous information if ( ($update_name == 1) or ($update_date == 1) or ($row['author'] == '') ) { $query = 'UPDATE '.PREFIX_TABLE.'images'; if ($update_name == 1) $query.= 'SET name = ' .$name; if ($update_date == 1) $query.= 'SET date_creation = ' .$date; if ($update_comment == 1) $query.= 'SET comment = ' .$comment; if ($row['author'] == '') $query.= 'SET author = \'Eric\' '; $query.= 'WHERE id = ' .$id; $query.= ';'; mysql_query( $query ); } } } mysql_close();
What's wrong in that ?
It doesn't work and even crash mysql (" Fatal error: Maximum execution time of 30 seconds exceeded in c:\documents and settings\localhost\phpwebgallery\auto_name.php on line 46")
It seem's there there is (are) error (s) in my code for database connection. It is allowed to update 3000 fields of a table in a loop ?
Offline
Without adding any change, I get the same error message because I try to process a full update on more than 5000 photos. Indeed, it seems that if it takes too long, then you get this error.
On the other hand, it looks like the update is, each time, partly done... so that if I ask for the same update a few times, eventually it is completely done! The data is entered in the database a few thousand entries at a time, in fact.
If someone knows how to get rid of this fatal error, I take it! I wouls still prefer to do it in one shot.
You may be interested in reading this post.
Synchronizing metadata TIMEOUT and upper limit tests/results
http://forum.phpwebgallery.net/viewtopi … 752#p20752
Offline