⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 photos.php

📁 这是一个joomla系统的插件, 这是一个joomla系统的插件
💻 PHP
📖 第 1 页 / 共 3 页
字号:
//    echo '<pre>';//    print_r($_FILES);//    echo '</pre>';    $time = time();    $known_images = array('image/pjpeg', 'image/jpeg', 'image/jpg', 'image/png', 'image/x-png', 'image/gif');        if(!empty($_FILES['photo']['name'])){ // single file upload      if($_FILES['photo']['error'] > 0){ //error during upload        switch ($_FILES['photo']['error']){          case UPLOAD_ERR_INI_SIZE:            $err_msg = 'The uploaded file exceeds the upload_max_filesize directive in php.ini.';            break;          case UPLOAD_ERR_FORM_SIZE:            $err_msg = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.';            break;          case UPLOAD_ERR_PARTIAL:            $err_msg = 'The uploaded file was only partially uploaded.';            break;          case UPLOAD_ERR_NO_FILE:            $err_msg = 'No file was uploaded.';            break;          case UPLOAD_ERR_NO_TMP_DIR:            $err_msg = 'Missing a temporary folder.';            break;          case UPLOAD_ERR_CANT_WRITE:            $err_msg = 'Failed to write file to disk.';            break;          case UPLOAD_ERR_EXTENSION:            $err_msg = 'File upload stopped by extension.';            break;          default:            $err_msg = 'Unknown error';            break;        }                echo "<script> alert('Upload error for file ". $_FILES['photo']['name']. ".\\nError message: " . $err_msg . "'); document.location.href='index2.php?option=" . $option . "&act=photos&task=new'; </script>\n";  			exit();      }            if(!in_array($_FILES['photo']['type'], $known_images)){        echo "<script> alert('Photo type: ". $_FILES['photo']['type']. " is an unknown photo type'); document.location.href='index2.php?option=" . $option . "&act=photos&task=new'; </script>\n";  			exit();      }            photos::addFile($ftp, $_FILES['photo']['tmp_name'], $_FILES['photo']['name'], $imagename, $_FILES['photo']['type'], $description, $cid, $state);  		      if($redirect){    		mosRedirect('index2.php?option=' . $option . '&act=photos&task=new', 'Photo saved successfully');      }    }    if(!empty($_FILES['zip']['name'])){ //zip file upload      $known = array('application/x-zip', 'application/x-zip-compressed');      if($_FILES['zip']['error'] > 0){ //error during upload        switch ($_FILES['zip']['error']){          case UPLOAD_ERR_INI_SIZE:            $err_msg = 'The uploaded file exceeds the upload_max_filesize directive in php.ini.';            break;          case UPLOAD_ERR_FORM_SIZE:            $err_msg = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.';            break;          case UPLOAD_ERR_PARTIAL:            $err_msg = 'The uploaded file was only partially uploaded.';            break;          case UPLOAD_ERR_NO_FILE:            $err_msg = 'No file was uploaded.';            break;          case UPLOAD_ERR_NO_TMP_DIR:            $err_msg = 'Missing a temporary folder.';            break;          case UPLOAD_ERR_CANT_WRITE:            $err_msg = 'Failed to write file to disk.';            break;          case UPLOAD_ERR_EXTENSION:            $err_msg = 'File upload stopped by extension.';            break;          default:            $err_msg = 'Unknown error';            break;        }                echo "<script> alert('Upload error for file ". $_FILES['zip']['name']. ".\\nError message: " . $err_msg . "'); document.location.href='index2.php?option=" . $option . "&act=photos&task=new'; </script>\n";  			exit();      }      //      if(!in_array($_FILES['zip']['type'], $known)){//        echo "<script> alert('Archive type: ". $_FILES['zip']['type']. " is an unknown archive type'); window.history.go(-1); </script>\n";//  			exit();//      }      $tmpdir = '';      if(!mkdir($mainframe->getCfg('absolute_path') . '/media/' . $time)){        if(!mkdir('/tmp/' . $time)){          echo "<script> alert('Unable to create temporary extraction directory'); document.location.href='index2.php?option=" . $option . "&act=photos&task=new'; </script>\n";    			exit();        } else {          $tmpdir = '/tmp/' . $time;        }      } else {        $tmpdir = $mainframe->getCfg('absolute_path') . '/media/' . $time;      }            $iswin = (substr(PHP_OS, 0, 3) == 'WIN');            if (eregi( '.zip$', $_FILES['zip']['name'] )) {  			// Extract functions  			require_once( $mainframe->getCfg('absolute_path') . '/administrator/includes/pcl/pclzip.lib.php' );  			require_once( $mainframe->getCfg('absolute_path') . '/administrator/includes/pcl/pclerror.lib.php' );  			$zipfile = new PclZip( $_FILES['zip']['tmp_name'] );  			if($iswin) {  				define('OS_WINDOWS',1);  			} else {  				define('OS_WINDOWS',0);  			}    			$ret = $zipfile->extract( PCLZIP_OPT_PATH, $tmpdir );  			if($ret == 0) {  			  echo "<script> alert('Unrecoverable error: " . $zipfile->errorName(true) . " '); document.location.href='index2.php?option=" . $option . "&act=photos&task=new'; </script>\n";    			exit();  			}  		} else {  			require_once( $mainframe->getCfg('absolute_path') . '/includes/Archive/Tar.php' );  			$archive = new Archive_Tar( $_FILES['zip']['tmp_name'] );  			$archive->setErrorHandling( PEAR_ERROR_PRINT );    			if (!$archive->extractModify( $tmpdir, '' )) {  				echo "<script> alert('Extract error'); document.location.href='index2.php?option=" . $option . "&act=photos&task=new'; </script>\n";    			exit();  			}  		}  		  		$files = mosReadDirectory($tmpdir, '.', false, true);  		photos::sortFiles($files, $sort);  		  		if(sizeof($files) == 0){  		  echo "<script> alert('No files found in extracted archive'); document.location.href='index2.php?option=" . $option . "&act=photos&task=new'; </script>\n";  			exit();  		}  		  		$added_files = 0;      for($i=0,$n=count($files);$i<$n;$i++){        $file = $files[$i];        $file = str_replace("\\", '/', $file);                if(!is_file($file)){          continue;        }                $name = explode("/", $file);                $res = getimagesize($file);        $filetype = $res['mime'];        if(in_array($filetype, $known_images)){          photos::addFile($ftp, $file, $name[sizeof($name) - 1], $imagename, $filetype, $description, $cid, $state);        }                $added_files++;                unlink($file);      }            rmdir($tmpdir);            if($redirect){        mosRedirect('index2.php?option=' . $option . '&act=photos&task=new', $added_files . ' images added successfully');      }    }        $dir = mosGetParam($_REQUEST, 'dir', '');    if($dir != $mainframe->getCfg('absolute_path')){  //read directory      if(!file_exists($dir)){        echo "<script> alert('Directory $dir does not exist'); document.location.href='index2.php?option=" . $option . "&act=photos&task=new'; </script>\n";  			exit();      }            if(!is_writable($mainframe->getCfg('absolute_path') . '/media/')){        if(!is_writable('/tmp/')){          echo "<script> alert('/tmp is not writable'); document.location.href='index2.php?option=" . $option . "&act=photos&task=new'; </script>\n";    			exit();        } else {          $tmpdir = '/tmp/';        }      } else {        $tmpdir = $mainframe->getCfg('absolute_path') . '/media/';      }            $files = mosReadDirectory($dir, '.', false, true);      photos::sortFiles($files, $sort);            if(sizeof($files) == 0){        echo "<script> alert('No files were found in $dir'); document.location.href='index2.php?option=" . $option . "&act=photos&task=new'; </script>\n";  			exit();      }            $added_files = 0;      for($i=0,$n=count($files);$i<$n;$i++){        $file = $files[$i];        $file = str_replace("\\", '/', $file);                if(!is_file($file)){          continue;        }                $name = explode("/", $file);                copy($file, $tmpdir . '/' . $name[sizeof($name) - 1]);                $res = getimagesize($tmpdir . '/' . $name[sizeof($name) - 1]);        $filetype = $res['mime'];                if(in_array($filetype, $known_images)){          photos::addFile($ftp, $tmpdir . '/' . $name[sizeof($name) - 1], $name[sizeof($name) - 1], $imagename, $filetype, $description, $cid, $state);        }                $added_files++;                unlink($tmpdir . '/' . $name[sizeof($name) - 1]);      }            if($redirect){        mosRedirect('index2.php?option=' . $option . '&act=photos&task=new', $added_files . ' files added successfully');      }    }  }    /**   * Resize an image   *   * @param string $file   * @param string $type   */  function resize($file, $type, $height, $width){    require(PATH_EASYGALLERY . '/configuration.php');        $img = false;    switch ($type){      case 'image/jpeg':      case 'image/jpg':      case 'image/pjpeg':        $img = imagecreatefromjpeg($file);        break;      case 'image/x-png':      case 'image/png':        $img = imagecreatefrompng($file);        break;      case 'image/gif':        $img = imagecreatefromgif($file);        break;    }        if(!$img){      return false;    }        $curr = @getimagesize($file);        $perc_w = $width / $curr[0];    $perc_h = $height / $curr[1];        if(($width > $curr[0]) || ($height > $curr[1])){      return;    }        if($perc_h > $perc_w){      $width = $width;      $height = round($curr[1] * $perc_w);    } else {      $height = $height;      $width = round($curr[0] * $perc_h);    }        $nwimg = imagecreatetruecolor($width, $height);    imagecopyresampled($nwimg, $img, 0, 0, 0, 0, $width, $height, $curr[0], $curr[1]);        switch ($type){      case 'image/jpeg':      case 'image/jpg':      case 'image/pjpeg':        imagejpeg($nwimg, $file);        break;      case 'image/x-png':      case 'image/png':        imagepng($nwimg, $file);        break;      case 'image/gif':        imagegif($nwimg, $file);        break;    }        imagedestroy($nwimg);    imagedestroy($img);  }    /**   * Add a file to the gallery   *   * @param pointer $ftp   * @param string $filepath   * @param string $filename   * @param string $imagename   * @param string $filetype   * @param string $description   * @param int $cid   * @param int $state   */  function addFile(&$ftp, $filepath, $filename, $imagename, $filetype, $description, $cid, $state){    global $database, $eg_ftp_path, $eg_image_path, $eg_original_path, $eg_thumbnail_path, $eg_ftp_disabled, $mainframe;    global $eg_max_height, $eg_max_width, $eg_thumbnail_height, $eg_thumbnail_width;        $time = time();        $filename = preg_replace('#\W^\.#is', '', $filename); //fix up name to get rid of spaces etc    $filename = strtolower($filename); //only lowercase        //store original    if($eg_ftp_disabled == 0){      //check if directory exists...      if(!$ftp->mkDir($eg_original_path, $cid)){        echo "<script> alert('Failed to create gallery directory.'); window.history.go(-1); </script>\n";        exit;      }            if(!$ftp->cd($eg_ftp_path . $eg_original_path . '/' . $cid)){        echo "<script> alert('Failed to change to gallery directory: ". $eg_ftp_path . $eg_original_path . '/' . $cid . "'); window.history.go(-1); </script>\n";        exit;      }            if(!$ftp->copy($filepath, $time . "_" . $filename)){ //move original        echo "<script> alert('Failed to copy original $filename to upload path.'); window.history.go(-1); </script>\n";        exit;      }          } else {      if(!is_writable($mainframe->getCfg('absolute_path') . '/' . $eg_original_path)){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -