コード例 #1
0
 function avatar($id)
 {
     $this->autoRender = false;
     App::import('Component', 'File');
     $file = new FileComponent();
     if (!is_dir(PRODUCTIMAGES . DS . 'tmp')) {
         $file->makeDir(PRODUCTIMAGES . DS . 'tmp');
     } else {
         $oldies = glob(PRODUCTIMAGES . DS . 'tmp' . DS . '*');
         foreach ($oldies as $o) {
             unlink($o);
         }
     }
     if (!empty($this->params['form']['Filedata'])) {
         if (strpos(strtolower(env('HTTP_USER_AGENT')), 'flash') === false || !$this->RequestHandler->isPost()) {
             exit;
         }
     }
     if (!empty($this->params['form']['Filedata'])) {
         $tmp = $this->params['form']['Filedata'];
         $ext = $file->returnExt($this->params['form']['Filedata']['name']);
         $fn = 'original.' . $ext;
         $the_temp = $this->params['form']['Filedata']['tmp_name'];
         $temp_path = PRODUCTIMAGES . DS . 'tmp' . DS . $fn;
         if (!is_dir(dirname($temp_path))) {
             $file->makeDir(dirname($temp_path));
         }
         if (in_array($ext, a('jpg', 'jpeg', 'jpe', 'gif', 'png'))) {
             if (is_uploaded_file($the_temp)) {
                 move_uploaded_file($the_temp, $temp_path);
             }
         }
     }
     exit(' ');
 }
コード例 #2
0
ファイル: File.php プロジェクト: alex-dwt/file
 /**
  * @inheritdoc
  * @throws InvalidCallException when trying to unset `as{Format}` property.
  */
 public function __unset($name)
 {
     if (!parent::canSetProperty($name) && $this->_parseFormatAlias($name) !== false) {
         throw new InvalidCallException('Unsetting read-only property: ' . get_class($this) . "::{$name}.");
     }
     parent::__unset($name);
 }
コード例 #3
0
 public function image()
 {
     $this->autoRender = false;
     if ($this->Auth->user()) {
         $user_id = $this->Auth->user('id');
         App::import('Component', 'File');
         $file = new FileComponent();
         if (!is_dir(PHOTOS)) {
             $file->makeDir(PHOTOS);
         }
         if (!is_dir(PHOTOS . DS . $user_id)) {
             $file->makeDir(PHOTOS . DS . $user_id);
         }
         if (!$this->request->is('post')) {
             exit;
         }
         if (!empty($this->request->params['form']['files'])) {
             $formfiles = $this->request->params['form']['files'];
             $the_files = $this->request->params['form']['files']['name'];
             $photos = array();
             foreach ($the_files as $key => $value) {
                 $the_file = str_replace(" ", "_", $the_files[$key]);
                 $the_file = ereg_replace("[^A-Za-z0-9._-]", "_", $the_file);
                 $the_temp = $formfiles['tmp_name'][$key];
                 $ext = $file->returnExt($the_file);
                 if (in_array($ext, array('jpg', 'jpeg', 'jpe', 'gif', 'png'))) {
                     if (is_uploaded_file($the_temp)) {
                         $this->Photo->create();
                         if ($this->Photo->save()) {
                             $id = $this->Photo->id;
                             $path = PHOTOS . DS . $user_id . DS . $id;
                             $lg_path = $path . DS . 'lg' . DS . $the_file;
                             $lg_temp = $lg_path . '.tmp';
                             if ($file->makeDir($path) && $file->setFolderPerms($user_id, $id) && move_uploaded_file($the_temp, $lg_temp)) {
                                 copy($lg_temp, $lg_path);
                                 unlink($lg_temp);
                                 list($meta, $captured) = $file->imageMetadata($lg_path);
                                 //                  $this->log($meta, LOG_DEBUG);
                                 $exposure = $file->parseMetaTags('exif:exposure', $meta);
                                 $iso = $file->parseMetaTags('exif:iso', $meta);
                                 $longitude = $file->parseMetaTags('exif:longitude', $meta);
                                 $aperture = $file->parseMetaTags('exif:aperture', $meta);
                                 $make = $file->parseMetaTags('exif:make', $meta);
                                 $model = $file->parseMetaTags('exif:model', $meta);
                                 //                  $keywords = str_replace(' ', ',', urldecode($keywords));
                                 //                  $keywords = ereg_replace("[^,A-Za-z0-9._-]", "", $keywords);
                                 $this->request->data['Photo']['id'] = $id;
                                 $this->request->data['Photo']['user_id'] = $user_id;
                                 $this->request->data['Photo']['src'] = $the_file;
                                 $this->request->data['Photo']['filesize'] = filesize($lg_path);
                                 $this->request->data['Photo']['captured'] = $captured;
                                 $this->request->data['Photo']['exposure'] = $exposure;
                                 $this->request->data['Photo']['iso'] = $iso;
                                 $this->request->data['Photo']['longitude'] = $longitude;
                                 $this->request->data['Photo']['aperture'] = $aperture;
                                 $this->request->data['Photo']['make'] = $make;
                                 $this->request->data['Photo']['model'] = $model;
                                 $this->request->data['Photo']['order'] = -1;
                                 $this->request->data['Photo']['title'] = "New Photo";
                             }
                         }
                     }
                 }
                 // append to array
                 $photos[] = $this->request->data;
             }
             // foreach
             if ($this->Photo->saveAll($photos)) {
                 $p = $this->set('_serialize', $photos);
                 $this->render(SIMPLE_JSON);
             }
         }
     }
 }
コード例 #4
0
 private function _use_preview($id, $use = false)
 {
     App::import('Component', 'File');
     $file = new FileComponent();
     define('TEMP_PATH', PRODUCTIMAGES . DS . 'tmp');
     define('DEST_PATH', PRODUCTIMAGES . DS . $id);
     $temp_files = glob(TEMP_PATH . DS . '*');
     if (count($temp_files) < 1) {
         return;
     }
     $fn = basename($temp_files[0]);
     $path_to_temp = TEMP_PATH . DS . $fn;
     $ext = $file->returnExt($fn);
     if ($use) {
         if (!is_dir(PRODUCTIMAGES)) {
             $file->makeDir(PRODUCTIMAGES);
         }
         if (!is_dir(DEST_PATH)) {
             $file->makeDir(DEST_PATH);
         } else {
             $oldies = glob(DEST_PATH . DS . 'original.*');
             foreach ($oldies as $o) {
                 unlink($o);
             }
             $oldies = glob(DEST_PATH . DS . 'cache' . DS . '*');
             foreach ($oldies as $o) {
                 unlink($o);
             }
         }
         $source = TEMP_PATH . DS . $fn;
         $dest = DEST_PATH . DS . $fn;
         $this->log('filename: ' . $fn, LOG_DEBUG);
         $this->log('source: ' . $source, LOG_DEBUG);
         $this->log('dest: ' . $dest, LOG_DEBUG);
         $this->log('DEST_PATH: ' . DEST_PATH, LOG_DEBUG);
         $ret = copy($source, $dest);
         $this->log('copy = ' . $ret, LOG_DEBUG);
         $this->Product->id = $id;
         $this->Product->saveField('image', $fn);
     }
     foreach ($temp_files as $o) {
         //      unlink($o);
     }
     return $ret;
 }