Difference between revisions of "Tutorial: PhpRunner 9.8 and Photo Display"
Line 107: | Line 107: | ||
</source> | </source> | ||
==How to compute dpi, width, height and store in MySQL DB== | ==How to compute dpi, width, height and store in MySQL DB== | ||
+ | ===Reproduced, Add page, "After Record Added" Event=== | ||
<br /> | <br /> | ||
::<source lang="php"> | ::<source lang="php"> | ||
− | + | ||
$fileInfozzz = $values["fileName"]; | $fileInfozzz = $values["fileName"]; | ||
Line 130: | Line 131: | ||
// get DPI info | // get DPI info | ||
$dpi = 72; | $dpi = 72; | ||
− | $cmd = 'identify -quiet -format "%x" '.$ | + | $cmd = 'identify -quiet -format "%x" '.$filePathzzz; |
@exec( escapeshellcmd($cmd), $data ); | @exec( escapeshellcmd($cmd), $data ); | ||
if($data && is_array($data)){ | if($data && is_array($data)){ | ||
Line 172: | Line 173: | ||
CustomQuery($sql); | CustomQuery($sql); | ||
− | } // | + | |
+ | </source> | ||
+ | <br /> | ||
+ | ===Originals, Add Page, "After Record Added" Event=== | ||
+ | <br /> | ||
+ | ::<source lang="php"> | ||
+ | |||
+ | $fileInfozzz = $values["fileName"]; | ||
+ | $dicozzz = explode( ",", $fileInfozzz ); | ||
+ | $fileNamezzz = str_replace( "[{", "", $dicozzz[0] ); | ||
+ | $fileNamezzz = str_replace( "\"", "", explode( ":", $fileNamezzz )[1] ); | ||
+ | $fileNamezzz = str_replace( "\\", "", $fileNamezzz ); | ||
+ | $filePathzzz = $_SERVER["DOCUMENT_ROOT"]. "/photos/" . $fileNamezzz; | ||
+ | $paramszzz = getimagesize( $filePathzzz ); | ||
+ | $widthzzz = $paramszzz[0]; | ||
+ | $heightzzz = $paramszzz[1]; | ||
+ | |||
+ | file_put_contents('php://stderr', print_r( "Originals\n============\nwidth = ", TRUE )); | ||
+ | file_put_contents('php://stderr', print_r( $widthzzz, TRUE )); | ||
+ | file_put_contents('php://stderr', print_r( "\nheight = ", TRUE )); | ||
+ | file_put_contents('php://stderr', print_r( $heightzzz, TRUE )); | ||
+ | file_put_contents('php://stderr', print_r( "\nfilePathzzz = ", TRUE )); | ||
+ | file_put_contents('php://stderr', print_r( $filePathzzz, TRUE )); | ||
+ | |||
+ | |||
+ | // get DPI info | ||
+ | $dpi = 72; | ||
+ | $cmd = 'identify -quiet -format "%x" '.$filePathzzz; | ||
+ | @exec( escapeshellcmd($cmd), $data ); | ||
+ | if($data && is_array($data)){ | ||
+ | $data = explode(' ', $data[0]); | ||
+ | if($data[1] == 'PixelsPerInch'){ | ||
+ | $dpi = $data[0]; | ||
+ | } elseif($data[1] == 'PixelsPerCentimeter'){ | ||
+ | $dpi = ceil($data[0] * 2.54); | ||
+ | }elseif($data[1] == 'Undefined'){ | ||
+ | $dpi = $data[0]; | ||
+ | } | ||
+ | } | ||
+ | $dpi = (int) $dpi; | ||
+ | |||
+ | file_put_contents('php://stderr', print_r( "\n\n\noriginals: dpi=", TRUE ) ); | ||
+ | file_put_contents('php://stderr', print_r( $dpi, TRUE )); | ||
+ | file_put_contents('php://stderr', print_r( "\nwidth = ", TRUE ) ); | ||
+ | file_put_contents('php://stderr', print_r( $widthzzz, TRUE )); | ||
+ | file_put_contents('php://stderr', print_r( "\nheight = ", TRUE ) ); | ||
+ | file_put_contents('php://stderr', print_r( $heightzzz, TRUE )); | ||
+ | file_put_contents('php://stderr', print_r( "\n", TRUE ) ); | ||
+ | |||
+ | // --- get last record added to reproduced table | ||
+ | $sql = "SELECT Id FROM originals ORDER BY Id DESC LIMIT 1"; | ||
+ | $res = CustomQuery($sql); | ||
+ | $data = db_fetch_array($res); | ||
+ | $Id = (int) $data["Id"]; | ||
+ | |||
+ | //--- display Id of last record | ||
+ | file_put_contents('php://stderr', "\n" ); | ||
+ | file_put_contents('php://stderr', print_r( $data["Id"], TRUE )); | ||
+ | file_put_contents('php://stderr', "\n" ); | ||
+ | |||
+ | //--- update width and height of record just added --- | ||
+ | $sql = "Update originals set dpi='$dpi', width='$widthzzz'," . | ||
+ | " height='$heightzzz' where Id=".$Id; | ||
+ | CustomQuery($sql); | ||
+ | |||
</source> | </source> |