I decided to write this mod because, I often miss to rotate some pictures and I don't want to go to my phpMyAdmin every time to update the database... ;)
############################################################## ## MOD Title: Refresh sizes ## MOD Author: Whiler ## MOD Description: Get width, height and filesize directly from the picture and update the image table ## MOD Version: 1.0.0 ## ## Installation Level: Easy ## Installation Time: 10 Minutes ## Files To Edit: picture_modify.php, picture_modify.vtp, and used languages files ## System requirements : n/a ############################################################## ## Author Notes: I'm lazy... so I prefer do it one time good, than several times ;) ## ############################################################## ## MOD History: ## ## 2004-12-29 - Version 1.0.0 ## - Successfully tested with PhpWebGallery 1.3.4, PHP 4.3.3 and 4.3.10, ovh and free 4 remote sites ## ############################################################## ## Before Adding This MOD To Your gallery, You Should Back Up All Files Related To This MOD ############################################################## # #-----[ OPEN ]------------------------------------------ ./admin/picture_modify.php # # #-----[ AFTER ]------------------------------------------ # include_once( './include/isadmin.inc.php' ); //--------------------------------------------------------- update informations $errors = array(); // first, we verify whether there is a mistake on the given creation date if ( isset( $_POST['creation_date'] ) and $_POST['creation_date'] != '' ) { if ( !check_date_format( $_POST['creation_date'] ) ) array_push( $errors, $lang['err_date'] ); } if ( isset( $_POST['submit'] ) ) { # #-----[ ADD ]------------------------------------------ # // Le support des URL a été ajouté en PHP 4.0.5. if ( isset( $_POST['refreshsizeinfos'] ) ) { // Récupération des informations utiles concernant l'image $query = 'SELECT storage_category_id, file FROM '.PREFIX_TABLE.'images WHERE id = '.$_GET['image_id']; $row = mysql_fetch_array( mysql_query( $query ) ); $fullfilename = get_complete_dir( $row['storage_category_id'] ); $result = get_cat_info( $row['storage_category_id'] ); if ( $result['site_id'] == 1 ) $fullfilename = '.'.$fullfilename; $fullfilename.=$row['file']; // Récupère les dimensions de l'image $image_size = @getimagesize( $fullfilename );; // Calcule la taille du fichier if ( $result['site_id'] == 1 ) { // Calcul local $filesize = filesize( $fullfilename ); } else { // Calcul distant $timeout = 5; $url = parse_url($fullfilename); if ($fp = @fsockopen($url['host'], ($url['port'] ? $url['port'] : 80), $errno, $errstr, $timeout)) { fwrite($fp, 'HEAD '.$url['path'].$url['query']." HTTP/1.0\r\nHost: ".$url['host']."\r\n\r\n"); stream_set_timeout($fp, $timeout); while (!feof($fp)) { $filesize = fgets($fp, 4096); if (stristr($filesize, 'Content-Length') !== false) { $filesize = trim(substr($filesize, 16)); break; } } fclose ($fp); } $filesize = is_numeric($filesize) ? $filesize : -1; } $filesize = floor( $filesize / 1024 ); if (( $image_size[0] != '' )&&( $image_size[1] != '' )) { // Echange des valeurs $query = 'UPDATE '.PREFIX_TABLE.'images'; $query.= ' SET width = '.$image_size[0].', height = '.$image_size[1]; if ($filesize>-1) { $query.=', filesize = '.$filesize; } $query.=' WHERE id = '.$_GET['image_id']; mysql_query( $query ); } } # #-----[ FIND ]------------------------------------------ # 'cat_image_info','category_representative' # #-----[ REPLACE WITH ]------------------------------------------ # 'cat_image_info','category_representative','refresh_size_infos' ); # #-----[ OPEN AND UPDATE ALL YOUR TEMPLATES ]------------------------------------------ # ./template/ALL YOUR TEMPLATE NAME/admin/picture_modify.vtp # #-----[ FIND ]------------------------------------------ # <td>{#f_size}</td> # #-----[ REPLACE WITH ]------------------------------------------ # <td>{#f_size} [ <input type="checkbox" name="refreshsizeinfos" value="0" /> {#refresh_size_infos} ]</td> # #-----[ OPEN AND UPDATE ALL YOUR LANGUAGE FILES ]------------------------------------------ # ./language/english.php # #-----[ AFTER ]------------------------------------------ # $lang['size'] = 'Dimensions'; # #-----[ ADD ]------------------------------------------ # $lang['refresh_size_infos'] = 'Refresh sizes'; # #-----[ SAVE/CLOSE ALL FILES ]------------------------------------------ # # EoM
Offline
Warning... I don't know if PHPWebGallery is compatible with PHP3.. but the MOD uses at least, the 4.0.5 !
Whiler wrote:
## System requirements : PHP 4.0.5.
Offline
Thanks for your MOD, I'm sure it will be usefull :-) Thank you also for writting your MOD as recommended, it's very clean and readable.
By the way : you can edit your first post if you need to change some informations
Offline
You are welcome... ;o))
I forget to tell a detail...
Sometimes, it seems to not work.. If it happens to someone, just think to refresh the picture in your browser after your upload because your browser send the old one (in its cache)...
Offline
good work
works great
Offline