Nessuna descrizione

uploadify.php 1.9KB

    <?php include_once("image.php") ?> <?php define('__BASE__', dirname(__FILE__)); if (!empty($_FILES)) { $tempFile = $_FILES['Filedata']['tmp_name']; $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/'; //$targetPath = '/mnt/xvdb1/tamron' . $_REQUEST['folder'] . '/'; $targetPath = str_replace('//','/',$targetPath); $new_file_name = new_name( $_FILES['Filedata']['name']); $targetFile = $targetPath. $new_file_name; $res = mkdir($targetPath, 0777, true); recurDirs($targetPath, false); //防止中文文件名乱码 $res = move_uploaded_file($tempFile, $targetFile); //返回文件相对地址 $water = 'water.gif'; $img = new image(); $img->param($targetFile)->water($targetFile,$water,9); echo get_relative_path($targetFile); } function new_name($filename){ $ext = pathinfo($filename); $ext = $ext['extension']; $name = basename($filename,$ext); $name = md5($name.time()).'.'.$ext; return $name; } function get_relative_path($path,$dir = 'data'){ $strlen = strlen(substr(__BASE__, 0, 17)); $path = substr($path, $strlen); return '/'.substr($path,strpos($path,$dir),strlen($path )); } function recurDirs($path, $isFile = false, $mode = 0777) { $dirArr = explode('/', $path); if (!is_array($dirArr) || empty($dirArr)) { return false; } // 过滤掉空目录 // $dirArr = Libs_Filter::clearEmptyValue($dirArr); if ($isFile) { array_pop($dirArr); } $dirStr = ''; foreach ($dirArr as $dir) { $dirStr .= '/' . $dir; if (!is_dir($dirStr)) { // @mkdir($dirStr, $mode, true); exec("mkdir -p {$dirStr}",$outPut,$returnVar); @chmod($dirStr, $mode); } } if ($isFile) { if (!file_exists($path)) { @touch($path, $mode); @chmod($path, $mode); } } return true; } ?>