Exemple #1
0
 protected function onUpload()
 {
     try {
         if (!$this->options['upload']) {
             throw new FileManagerException('disabled');
         }
         if (empty($this->get['directory']) || function_exists('UploadIsAuthenticated') && !UploadIsAuthenticated($this->get)) {
             throw new FileManagerException('authenticated');
         }
         $dir = $this->getDir($this->get['directory']);
         $name = pathinfo(File_Upload::exists('Filedata') ? $this->getName($_FILES['Filedata']['name'], $dir) : null, PATHINFO_FILENAME);
         $ftp = new File_FTP($this->registry);
         $file = File_Upload::move('Filedata', $dir . '/', array('name' => $name, 'extension' => $this->options['safe'] && $name && in_array(strtolower(pathinfo($_FILES['Filedata']['name'], PATHINFO_EXTENSION)), array('exe', 'dll', 'php', 'php3', 'php4', 'php5', 'phps')) ? 'txt' : null, 'size' => $this->options['maxUploadSize'], 'mimes' => $this->getAllowedMimeTypes(), 'ftp' => $ftp));
         if (File_Utility::startsWith(File_Upload::mime($file), 'image/') && !empty($this->get['resize'])) {
             $ftp_file = $this->getFTPPath($ftp->public_html, $file);
             $ftp->chmod($ftp_file, 0646);
             $img = new File_Image($file);
             $size = $img->getSize();
             if ($size['width'] > 800) {
                 $img->resize(800)->save();
             } elseif ($size['height'] > 600) {
                 $img->resize(null, 600)->save();
             }
             $ftp->chmod($ftp_file, 0644);
         }
         echo json_encode(array('status' => 1, 'name' => pathinfo($file, PATHINFO_BASENAME)));
     } catch (UploadException $e) {
         echo json_encode(array('status' => 0, 'error' => '${upload.' . $e->getMessage() . '}'));
     } catch (FileManagerException $e) {
         echo json_encode(array('status' => 0, 'error' => '${upload.' . $e->getMessage() . '}'));
     }
 }