function getExifData($matche_img) { // due to the error occurred when if the path includes blank $image_path = urldecode($matche_img[3]); // return if not exists if (!file_exists($image_path)) { return; } $file_ext = array_pop(explode('.', $image_path)); if (strtolower($file_ext) != 'jpg') { return $matche_img[0]; } // Retrieve information for caching $file_md5 = md5_file($image_path); $file_size = filesize($image_path); // The path to the cache directory $cache_path = './files/cache/addon_exif/'; $cache_file = sprintf('%s_%s.cache.php', $file_size, $file_md5); unset($cache_exif_data); $cache_exif_data =& getExifCache($cache_path, $cache_file); if ($cache_exif_data) { $exif_data =& $cache_exif_data; } else { require_once $addon_path . 'phpexifrw/exifReader.php'; $er = new phpExifReader($image_path); $exif_data =& $er->getImageInfo(); } if (!$cache_exif_data) { setExifCache($cache_path, $cache_file, $exif_data); } $return_exif =& returnExifInfo($exif_data); return $matche_img[0] . $return_exif; }
function exif_parse_file($filename) { global $CONFIG; if (!is_readable($filename)) { return false; } $size = @getimagesize($filename); if ($size[2] != 2) { return false; } // Not a JPEG file //Check if we have the data of the said file in the table $sql = "SELECT * FROM {$CONFIG['TABLE_EXIF']} " . "WHERE filename = \"{$filename}\""; $result = db_query($sql); if (mysql_num_rows($result)) { $row = mysql_fetch_array($result); mysql_free_result($result); $exifParsed = unserialize($row["exifData"]); return $exifParsed; } // No data in the table - read it from the image file $exifObj = new phpExifReader($filename); $exif = $exifObj->getImageInfo(); $exifParsed = array(); $Make = isset($exif['make']); $Model = isset($exif['model']); if (isset($exif['make']) && isset($exif['model'])) { $exifParsed['Camera'] = trim($exif['make']) . " - " . trim($exif['model']); } if (isset($exif['DateTime'])) { $exifParsed['DateTaken'] = $exif['DateTime']; } if (isset($exif['fnumber'])) { $exifParsed['Aperture'] = $exif['fnumber']; } if (isset($exif['exposureTime'])) { $exifParsed['ExposureTime'] = $exif['exposureTime']; } if (isset($exif['focalLength'])) { $exifParsed['FocalLength'] = $exif['focalLength']; } if (isset($exif['isoEquiv'])) { $exifParsed['ISO'] = $exif['isoEquiv']; } if (isset($exif['exifComment'])) { $comment = $exif['exifComment']; $exifParsed['Comment'] = $comment; // eregi_replace("ASCII"," ", $comment); } // Insert it into table for future reference $sql = "INSERT INTO {$CONFIG['TABLE_EXIF']} " . "VALUES ('{$filename}', '" . addslashes(serialize($exifParsed)) . "')"; $result = db_query($sql); return $exifParsed; }
function get_exif_size($filename, $image_name) { set_error_handler("on_error_no_output"); // is needed because error are most likly but we don't care about fields we don't even know $er = new phpExifReader($filename); $er->processFile(); $exif_info = $er->getImageInfo(); set_error_handler("on_error"); $size_array = array(); $size_array[2] = 2; if (isset($er->ImageInfo[TAG_EXIF_IMAGEWIDTH])) { $size_array[0] = $er->ImageInfo[TAG_EXIF_IMAGEWIDTH]; } else { $size_array[0] = 1024; debug("Size of image " . $image_name . " cannot be detected using 1024x768."); } if (isset($er->ImageInfo[TAG_EXIF_IMAGELENGTH])) { $size_array[1] = $er->ImageInfo[TAG_EXIF_IMAGELENGTH]; } else { $size_array[1] = 768; } return $size_array; }
/** * Lire toutes les exifs d'une image * et les memoriser en static pour optimisation * * @param string $fichier * @return array */ function extraire_exif($fichier) { static $mem_exif; if (isset($mem_exif[$fichier]) and $mem_exif[$fichier]) { return $mem_exif[$fichier]; } if (!file_exists($fichier)) { return array(); } $time = filemtime($fichier); $fichier_exif = sous_repertoire(_DIR_VAR, 'cache-exif') . md5($fichier . $time) . ".php"; // Systeme de cache pour les variables exif if (file_exists($fichier_exif)) { lire_fichier($fichier_exif, $cache); if ($mem_exif[$fichier] = unserialize($cache)) { return $mem_exif[$fichier]; } } include_spip("inc/exifReader"); $er = new phpExifReader($fichier); $er->processFile(); $mem_exif[$fichier] = $er->getImageInfo(); // Essayer de trouver aux:Lens $mem_exif[$fichier]["auxLens"] = str_replace(" mm", " ", lire_aux_lens($fichier)); // Completer GPS if (function_exists('exif_read_data')) { $exif_direc = @exif_read_data($fichier); // Si Latitude deja fixee, la traiter // Si la ref n'est ni N ni S, c'est une erreur (j'en trouve sur Flickr) if (!($exif_direc["GPSLatitudeRef"] == "N" || $exif_direc["GPSLatitudeRef"] == "S")) { unset($mem_exif[$fichier]["GPSLatitude"]); } if ($mem_exif[$fichier]["GPSLatitude"]) { $exif_direc["GPSLatitude"][0] = $mem_exif[$fichier]["GPSLatitude"]["Degrees"]; $exif_direc["GPSLatitude"][1] = $mem_exif[$fichier]["GPSLatitude"]["Minutes"] * 100 + round($mem_exif[$fichier]["GPSLatitude"]["Seconds"] / 60 * 100) . "/100"; $exif_direc["GPSLatitudeRef"] = $mem_exif[$fichier]["GPSLatitudeRef"]; } // Traiter la Latitude // Retourne GPSLatitude en degres, minutes, secondes // Retour GPSLatitudeInt en valeur entiere pour Google if (isset($exif_direc["GPSLatitude"])) { $deg = $exif_direc["GPSLatitude"][0]; if (strpos($deg, "/") > 0) { $deg = substr($deg, 0, strpos($deg, "/")); } $min = $exif_direc["GPSLatitude"][1]; if (strpos($min, "/") > 0) { $minutes = substr($min, 0, strpos($min, "/")); $rap = substr($min, strpos($min, "/") + 1, 12); $minutes = $minutes / $rap; $secondes = ($minutes - floor($minutes)) * 60; $minutes = floor($minutes); } $N_S = $exif_direc["GPSLatitudeRef"]; $mem_exif[$fichier]["GPSLatitude"] = $deg . "° {$minutes}" . "’" . " {$secondes}" . "” {$N_S}"; // Retourne aussi une valeur entiere pour Google Maps $GPSLatitudeInt = $deg + $min / 6000; if ($N_S == "S") { $GPSLatitudeInt = -1 * $GPSLatitudeInt; } $mem_exif[$fichier]["GPSLatitudeInt"] = $GPSLatitudeInt; } // Verifier que la precedente ref est E/W, sinon ne pas traiter if (!($exif_direc["GPSLongitudeRef"] == "E" || $exif_direc["GPSLongitudeRef"] == "W")) { unset($mem_exif[$fichier]["GPSLongitude"]); } if ($mem_exif[$fichier]["GPSLongitude"]) { $exif_direc["GPSLongitude"][0] = $mem_exif[$fichier]["GPSLongitude"]["Degrees"]; $exif_direc["GPSLongitude"][1] = $mem_exif[$fichier]["GPSLongitude"]["Minutes"] * 100 + round($mem_exif[$fichier]["GPSLongitude"]["Seconds"] / 60 * 100) . "/100"; $exif_direc["GPSLongitudeRef"] = $mem_exif[$fichier]["GPSLongitudeRef"]; } // Traiter longitude if (isset($exif_direc["GPSLongitude"])) { $deg = $exif_direc["GPSLongitude"][0]; if (strpos($deg, "/") > 0) { $deg = substr($deg, 0, strpos($deg, "/")); } $min = $exif_direc["GPSLongitude"][1]; if (strpos($min, "/") > 0) { $minutes = substr($min, 0, strpos($min, "/")); $rap = substr($min, strpos($min, "/") + 1, 12); $minutes = $minutes / $rap; $secondes = ($minutes - floor($minutes)) * 60; $minutes = floor($minutes); } $W_E = $exif_direc["GPSLongitudeRef"]; $mem_exif[$fichier]["GPSLongitude"] = $deg . "° {$minutes}" . "’" . " {$secondes}" . "” {$W_E}"; // Retourne aussi une valeur entiere pour Google Maps $GPSLongitudeInt = $deg + $min / 6000; if ($W_E == "W") { $GPSLongitudeInt = -1 * $GPSLongitudeInt; } $mem_exif[$fichier]["GPSLongitudeInt"] = $GPSLongitudeInt; } } ecrire_fichier($fichier_exif, serialize($mem_exif[$fichier])); return $mem_exif[$fichier]; }
function save() { global $DB, $FUNCS, $AUTH, $Config; // ensure the person setting levels is privileged enough //if( $this->access_level > $AUTH->user->access_level ){ if ($this->get_access_level($inherited) > $AUTH->user->access_level) { //take into account access control placed on template and folders die("Cheating?!"); } $DB->begin(); // Pre-save.. // Adjust system fields. // If name empty, we create it from title field if set $title = trim($this->fields[0]->get_data()); $name = trim($this->fields[1]->get_data()); if ($this->tpl_nested_pages || $this->fields[1]->modified || $name == '' && $title != '') { $this->_lock_template(); // serialize access.. lock template } if ($name == '' && $title != '') { $name = $FUNCS->get_clean_url($title); // verify the name does not already exist $unique = false; $unique_id = 1; $orig_name = $name; while (!$unique) { $rs = $DB->select(K_TBL_PAGES, array('id'), "page_name='" . $DB->sanitize($name) . "' and NOT id=" . $DB->sanitize($this->id) . " and template_id='" . $DB->sanitize($this->tpl_id) . "'"); if (!count($rs)) { $unique = true; } else { $name = $orig_name . '-' . $unique_id++; } } $this->fields[1]->store_posted_changes($name); } $this->fields[0]->data = $title; // Folder ID $folder_id = intval($this->fields[2]->get_data()); if (!$folder_id) { $this->fields[2]->store_posted_changes('-1'); } // Publish date $publish_date = trim($this->fields[3]->get_data()); if ($publish_date != '0000-00-00 00:00:00') { $publish_date2 = $FUNCS->make_date($publish_date); if ($publish_date != $publish_date2) { $this->fields[3]->store_posted_changes($publish_date2); } } // Access level $access_level = intval($this->fields[4]->get_data()); if ($access_level < 0) { $access_level = 0; } if ($access_level > $AUTH->user->access_level) { $access_level = $AUTH->user->access_level; } $this->fields[4]->data = $access_level; // Weight field of nested pages.. if ($this->tpl_nested_pages) { $weight = trim($this->fields[7]->get_data()); if (!$weight || $this->fields[6]->modified) { // if new page or parent page changed // Calculate a weight that will place it below the last child of its parent $tree = $FUNCS->get_nested_pages($this->tpl_id, $this->tpl_name, $this->tpl_access_level); $nested_parent_id = $this->fields[6]->data; $nested_parent_page = $nested_parent_id != -1 ? $tree->find_by_id($nested_parent_id) : $tree; if (!$nested_parent_page) { die('ERROR: Parent page ' . $nested_parent_id . ' not found'); } $this->fields[7]->store_posted_changes(count($nested_parent_page->children) + 1); $refresh_tree = 1; // signal to add the new page into tree } // If pointer-page, fill details of the link if ($this->fields[12]->modified || $this->fields[13]->modified) { $this->fields[13]->store_posted_changes($FUNCS->analyze_link($this->fields[12]->get_data())); $this->fields[13]->modified = 1; $this->fields[12]->modified = 1; //mutually dependent } } // Weight of a gallery page. Make it the last in its folder. if ($this->tpl_gallery) { //todo } // Validate all fields before persistng changes $errors = 0; for ($x = 0; $x < count($this->fields); $x++) { $f =& $this->fields[$x]; $f->page_id = $this->id; if (!$f->validate()) { $errors++; } } if ($errors) { $DB->rollback(); return $errors; } if ($this->id == -1) { // New page. Create a record for it first. $last_id = $this->create($title, $name); if ($FUNCS->is_error($last_id)) { die("Failed to insert record for new page in K_TBL_PAGES"); } $this->id = $last_id; $rs = $DB->select(K_TBL_PAGES, array('*'), "id='" . $DB->sanitize($this->id) . "'"); if (!count($rs)) { die("Failed to insert record for new page in K_TBL_PAGES"); } $rec = $rs[0]; foreach ($rec as $k => $v) { $this->{$k} = $v; } unset($this->template_id); } $arr_update = array(); $arr_custom_fields = array(); $arr_fulltext_update = array(); unset($f); for ($x = 0; $x < count($this->fields); $x++) { $f =& $this->fields[$x]; if (defined('K_PHP_4') && $last_id) { $f->page->id = $this->id; } // PHP4 loses reference of new parent page ?? if ($f->modified) { if ($f->system) { $name = substr($f->name, 2); // remove the 'k_' prefix from system fields $prev_value = $this->{$name}; $this->{$name} = $arr_update[$name] = $f->get_data_to_save(); // if folder changed, have to set new parents if ($name == 'page_folder_id') { if ($this->page_folder_id != -1) { // set the page's containing folder (if the page resides in any) $this->folder =& $this->folders->find_by_id($this->page_folder_id); if (!$this->folder) { die('ERROR: Folder id ' . $this->page_folder_id . ' not found'); } } else { unset($this->folder); } } elseif ($name == 'page_title') { $arr_fulltext_update['title'] = $FUNCS->strip_tags($f->get_data()); } elseif ($name == 'nested_parent_id' && $this->tpl_nested_pages) { // The children of the original parent of this nested page will require reordering.. post save processing. $reset_weights_of = $prev_value; } } else { if ($f->k_type == 'image') { // Resize $resized = 0; $domain_prefix = $Config['k_append_url'] . $Config['UserFilesPath'] . 'image/'; if (extension_loaded('gd') && function_exists('gd_info')) { $src = $f->get_data(); if (strpos($src, $domain_prefix) === 0) { // process image only if local $src = substr($src, strlen($domain_prefix)); if ($src) { $src = $Config['UserFilesAbsolutePath'] . 'image/' . $src; // is EXIF data required? if ($this->tpl_gallery && K_EXTRACT_EXIF_DATA && $f->name == 'gg_image') { require_once K_COUCH_DIR . 'includes/phpExifRW/exifReader.inc'; $exifreader = new phpExifReader($src); if (!($exifreader->errno || $exifreader->errorno)) { $exifreader->ImageReadMode = 1; $exifdata = $FUNCS->filterExif($exifreader->getImageInfo()); $resized = 1; // do not manipulate uploaded image if contains exif (GD destroys exif). } } if (!$resized) { // OK to resize now $dest = $src; $w = $f->width; $h = $f->height; $crop = $f->crop; $enforce_max = $crop ? 0 : $f->enforce_max; // make crop and enforce_max mutually exclusive $quality = $f->quality; $res = k_resize_image($src, $dest, $w, $h, $crop, $enforce_max, $quality); if ($FUNCS->is_error($res)) { //$f->err_msg = $res->err_msg; //$errors++; // TODO: Non critical error. Will continue but have to report. } else { $resized = 1; // signal ok for creating thumbnail } } } } } // Find any associated thumbnail fields and update thumbnails (only for local files) for ($t = 0; $t < count($this->fields); $t++) { $tb =& $this->fields[$t]; if (!$tb->system && $tb->k_type == 'thumbnail' && $tb->assoc_field == $f->name) { if ($resized) { // create thumbnail $dest = null; $w = $tb->width; $h = $tb->height; // Make provision for enforce max. Make crop & enforce_max exclusive. $enforce_max = $tb->enforce_max; $crop = $enforce_max ? 0 : 1; $quality = $tb->quality; $thumbnail = k_resize_image($src, $dest, $w, $h, $crop, $enforce_max, $quality); if ($FUNCS->is_error($thumbnail)) { //$tb->err_msg = $thumbnail->err_msg; //$errors++; // TODO: Non critical error. Will continue but have to report. } else { $tb->modified = 1; $path_parts = $FUNCS->pathinfo($f->get_data()); $img_path = $path_parts['dirname'] . '/'; $img_path = substr($img_path, strlen($domain_prefix)); if ($img_path) { $thumbnail = $img_path . $thumbnail; } $tb->data = ':' . $thumbnail; // add marker $arr_custom_fields[$tb->id]['data'] = $tb->data; $arr_custom_fields[$tb->id]['type'] = $tb->search_type; $arr_custom_fields[$tb->id]['strip_domain'] = 1; } } else { $tb->data = ''; $arr_custom_fields[$tb->id]['data'] = ''; $arr_custom_fields[$tb->id]['type'] = $tb->search_type; } } unset($tb); } // Update meta data of gallery pages if ($this->tpl_gallery && $f->name == 'gg_image') { if ($resized) { clearstatcache(); $path_parts = $FUNCS->pathinfo($f->get_data()); $arr_update['file_name'] = $path_parts['basename']; $arr_update['file_ext'] = $path_parts['extension']; $arr_update['file_size'] = @filesize($src); if (is_array($exifdata) && count($exifdata)) { $arr_update['file_meta'] = $FUNCS->serialize($exifdata); } else { $arr_update['file_meta'] = ''; } } else { $arr_update['file_name'] = ''; $arr_update['file_ext'] = ''; $arr_update['file_size'] = 0; $arr_update['file_meta'] = ''; } } } if ($f->k_type != 'thumbnail') { // all the rest if ($f->k_type == 'image' || $f->k_type == 'file') { $arr_custom_fields[$f->id]['data'] = $f->data; // raw data without domain info $arr_custom_fields[$f->id]['strip_domain'] = 1; } else { $arr_custom_fields[$f->id]['data'] = $f->get_data_to_save(); } $arr_custom_fields[$f->id]['type'] = $f->search_type; if ($f->udf) { $arr_custom_fields[$f->id]['not_searchable'] = !$FUNCS->udfs[$f->k_type]['searchable']; $arr_custom_fields[$f->id]['search_data'] = $f->get_search_data(); } else { // core types if ($f->k_type == 'textarea' && $f->no_xss_check || $f->k_type == 'password') { $arr_custom_fields[$f->id]['not_searchable'] = 1; // code & password exempt .. } } } } } unset($f); } $arr_update['modification_date'] = $FUNCS->get_current_desktop_time(); // update page record $rs = $DB->update(K_TBL_PAGES, $arr_update, "id='" . $DB->sanitize($this->id) . "'"); if ($rs == -1) { die("ERROR: Unable to save data in K_TBL_PAGES"); } // update the custom fields if (count($arr_custom_fields)) { foreach ($arr_custom_fields as $k => $v) { $arr_custom_update = array('value' => $v['data']); if ($v['type'] == 'text') { $data_table = K_TBL_DATA_TEXT; if (isset($v['search_data'])) { // udf $arr_custom_update['search_value'] = $v['not_searchable'] == 1 ? '' : $FUNCS->strip_tags($v['search_data']); } else { // core types if ($v['strip_domain'] && substr($v['data'], 0, 1) == ':') { $arr_custom_update['search_value'] = substr($v['data'], 1); //..or should the entire path be stripped? } else { $arr_custom_update['search_value'] = $v['not_searchable'] == 1 ? '' : $FUNCS->strip_tags($v['data']); //TODO: strip shortcodes } } } else { $data_table = K_TBL_DATA_NUMERIC; } $rs = $DB->update($data_table, $arr_custom_update, "page_id='" . $DB->sanitize($this->id) . "' AND field_id='" . $DB->sanitize($k) . "'"); if ($rs == -1) { die("ERROR: Unable to save data in K_TBL_DATA"); } } // refresh the custom fields before displaying back $this->_fill_custom_fields(); // get the consolidated text data for this page (only from 'textarea', 'richtext' and 'text' editable regions) $full_text = ''; $rs = $DB->select(K_TBL_DATA_TEXT . ' dt, ' . K_TBL_FIELDS . ' f ', array('field_id', 'f.k_type as field_type', 'search_value'), "dt.page_id='" . $DB->sanitize($this->id) . "' AND dt.field_id=f.id"); if (count($rs)) { foreach ($rs as $rec) { if (($rec['field_type'] == 'textarea' || $rec['field_type'] == 'richtext' || $rec['field_type'] == 'text' || !$FUNCS->is_core_type($rec['field_type'])) && $rec['search_value']) { $full_text .= $rec['search_value'] . ' '; } } } $arr_fulltext_update['content'] = $full_text; } // update modification time_stamp $this->modification_date = $arr_update['modification_date']; // update full-text MyISAM table for searching if (count($arr_fulltext_update)) { $rs = $DB->update(K_TBL_FULLTEXT, $arr_fulltext_update, "page_id='" . $DB->sanitize($this->id) . "'"); if ($rs == -1) { die("ERROR: Unable to update data in K_TBL_FULLTEXT"); } } // post save processing.. adjust weights of remaining children of the previous parent of this nested page. if ($reset_weights_of) { $this->reset_weights_of($reset_weights_of); } elseif ($refresh_tree) { $FUNCS->get_nested_pages($this->tpl_id, $this->tpl_name, $this->tpl_access_level, 'weightx', 'asc', 1); } $DB->commit(); // Invalidate cache //$FUNCS->invalidate_cache(); return $errors; }
function UploadFile($dir, $type) { $dir = $this->AccessDir($dir, $type); if(!$dir) return false; if(!is_dir($dir.'/.thumbs')) { mkdir($dir.'/.thumbs'); } $dbfile = $dir.'/.thumbs/.db'; if(is_file($dbfile)) { $dbfilehandle = fopen($dbfile, "r"); $dblength = filesize($dbfile); if($dblength>0) $dbdata = fread($dbfilehandle, $dblength); fclose($dbfilehandle); //$dbfilehandle = fopen($dbfile, "w"); } else { //$dbfilehandle = fopen($dbfile, "w"); } if(!empty($dbdata)) { $files = unserialize($dbdata); } else $files = array(); //Файл из flash-мультизагрузки if(isset($_POST['Filename'])) { //Тип (изображение/файл) $pathtype = $_POST['pathtype']; if (strpos($_POST['Filename'], '.') !== false) { $extension = end(explode('.', $_POST['Filename'])); $filename = substr($_POST['Filename'], 0, strlen($_POST['Filename']) - strlen($extension) - 1); } else { header('HTTP/1.1 403 Forbidden'); exit(); } if($pathtype == 'images') $allowed = $this->ALLOWED_IMAGES; elseif($pathtype == 'files') $allowed = $this->ALLOWED_FILES; //Если не подходит разрешение файла if(!in_array(strtolower($extension),$allowed)) { header('HTTP/1.1 403 Forbidden'); exit(); } $md5 = md5_file($_FILES['Filedata']['tmp_name']); $file = $md5.'.'.$extension; //Проверка на изображение if($pathtype == 'images') { $files[$file]['imageinfo'] = getimagesize($_FILES['Filedata']['tmp_name']); if(empty($files[$file]['imageinfo'])) { header('HTTP/1.1 403 Forbidden'); exit(); } } if(!copy($_FILES['Filedata']['tmp_name'],$dir.'/'.$file)) { header('HTTP/1.0 500 Internal Server Error'); exit(); } $link = str_replace(array('/\\','//','\\\\','\\'),'/', '/'.str_replace(realpath(DIR_ROOT),'',realpath($dir.'/'.$file))); $path = pathinfo($link); $path = $path['dirname']; if($extension=='jpg' || $extension=='jpeg') { $er = new phpExifReader($dir.'/'.$file); $files[$file]['exifinfo'] = $er->getImageInfo(); $files[$file]['general'] = array( 'filename' => $file, 'name' => $filename, 'ext' => $extension, 'path' => $path, 'link' => $link, 'size' => filesize($dir.'/'.$file), 'date' => filemtime($dir.'/'.$file), 'width' => $files[$file]['imageinfo'][0], 'height'=> $files[$file]['imageinfo'][1], 'md5' => $md5 ); } else { $files[$file]['general'] = array( 'filename' => $file, 'name' => $filename, 'ext' => $extension, 'path' => $path, 'link' => $link, 'size' => filesize($dir.'/'.$file), 'date' => filemtime($dir.'/'.$file), 'width' => $files[$file]['imageinfo'][0], 'height'=> $files[$file]['imageinfo'][1], 'md5' => $md5 ); } } //Файлы из обычной загрузки else { sort($_FILES); $ufiles = $_FILES[0]; foreach ($ufiles['name'] as $k=>$v) { if($ufiles['error'][$k] != 0) continue; //Тип (изображение/файл) $pathtype = $_POST['pathtype']; if (strpos($ufiles['name'][$k], '.') !== false) { $extension = end(explode('.', $ufiles['name'][$k])); $filename = substr($ufiles['name'][$k], 0, strlen($ufiles['name'][$k]) - strlen($extension) - 1); } else { continue; } if($pathtype == 'images') $allowed = $this->ALLOWED_IMAGES; elseif($pathtype == 'files') $allowed = $this->ALLOWED_FILES; //Если не подходит расширение файла if(!in_array(strtolower($extension),$allowed)) { continue; } $md5 = md5_file($ufiles['tmp_name'][$k]); $file = $md5.'.'.$extension; //Проверка на изображение if($pathtype == 'images') { $files[$file]['imageinfo'] = getimagesize($ufiles['tmp_name'][$k]); if(empty($files[$file]['imageinfo'])) { header('HTTP/1.1 403 Forbidden'); exit(); } } if(!copy($ufiles['tmp_name'][$k],$dir.'/'.$file)) { continue; } $link = str_replace(array('/\\','//','\\\\','\\'),'/', '/'.str_replace(realpath(DIR_ROOT),'',realpath($dir.'/'.$file))); $path = pathinfo($link); $path = $path['dirname']; if($extension=='jpg' || $extension=='jpeg') { $er = new phpExifReader($dir.'/'.$file); $files[$file]['exifinfo'] = $er->getImageInfo(); $files[$file]['general'] = array( 'filename' => $file, 'name' => $filename, 'ext' => $extension, 'path' => $path, 'link' => $link, 'size' => filesize($dir.'/'.$file), 'date' => filemtime($dir.'/'.$file), 'width' => $files[$file]['imageinfo'][0], 'height'=> $files[$file]['imageinfo'][1], 'md5' => $md5 ); } else { $files[$file]['general'] = array( 'filename' => $file, 'name' => $filename, 'ext' => $extension, 'path' => $path, 'link' => $link, 'size' => filesize($dir.'/'.$file), 'date' => filemtime($dir.'/'.$file), 'width' => $files[$file]['imageinfo'][0], 'height'=> $files[$file]['imageinfo'][1], 'md5' => $md5 ); } } } $dbfilehandle = fopen($dbfile, "w"); fwrite($dbfilehandle, serialize($files)); fclose($dbfilehandle); return ''; }
public function getExtInfo() { $er = new phpExifReader($this->getPath()); return $er->getImageInfo(); }
/** * Get EXIF of file * * @param string $filename * @return array */ public function getExif($filename = null) { if (is_null($filename)) { return false; } App::import('Vendor', 'Nodeattachment.exif-reader.php'); $er = new phpExifReader($filename); $er->processFile(); return $er->getImageInfo(); }