/** * swfupload 多图上传 */ public function swfupload2() { if (IS_POST) { //上传处理类 $config = array('rootPath' => './' . C("UPLOADPATH"), 'savePath' => '', 'maxSize' => 11048576, 'saveName' => array('uniqid', ''), 'exts' => array('jpg', 'gif', 'png', 'jpeg', "txt", 'zip'), 'autoSub' => false); $upload = new \Think\Upload($config); $info = $upload->upload(); //开始上传 if ($info) { //上传成功 //写入附件数据库信息 $first = array_shift($info); if (!empty($first['url'])) { $url = $first['url']; } else { $url = C("TMPL_PARSE_STRING.__UPLOAD__") . $first['savename']; } //裁剪图片 import("Resizeimage", UTIl); $resize = new \Resizeimage(); $resize->initAttribute($config['rootPath'], 600, 600, 1); $cutimg = $resize->resize($first['savename']); echo "1," . $url . "," . '1,' . $first['name']; exit; } else { //上传失败,返回错误 exit("0," . $upload->getError()); } } else { $this->display(':swfupload2'); } }
function sp_check_thumb($url) { $file = explode("/", $url); $count = count($file); $fileName = $file[$count - 1]; $fileCata = $file[$count - 2]; $fileThumb = './data/upload/' . $fileCata . '/thumb/' . $fileName; if (!file_exists($fileThumb)) { import("Resizeimage", UTIl); $resize = new \Resizeimage(); $path = './data/upload/' . $fileCata . '/'; $resize->initAttribute($path, 640, 640, 2); $result = $resize->resize($fileName); if ($result) { return $fileThumb; } else { return $url; } } else { return $fileThumb; } }
public function ajaxImageUpload() { echo $prd_id = $this->input->post('prd_id'); $valid_formats = array("jpg", "png", "gif", "bmp", "jpeg"); if (isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST") { //$uploaddir = "uploads/"; $uploaddir = "server/php/rental/"; //a directory inside foreach ($_FILES['photos']['name'] as $name => $value) { $filename = stripslashes($_FILES['photos']['name'][$name]); $size = filesize($_FILES['photos']['tmp_name'][$name]); $width_height = getimagesize($_FILES['photos']['tmp_name'][$name]); //get the extension of the file in a lower case format $ext = $this->getExtension($filename); $ext = strtolower($ext); if ($width_height[0] > 200) { if (in_array($ext, $valid_formats)) { if ($size > 0) { $renameArr = explode('.', $filename); $imgTitle = strtolower($renameArr[0]); $imgTitle = mysql_real_escape_string($imgTitle); $imgTitle = trim($imgTitle); $imgTitle = str_replace("'", "", $imgTitle); $imgTitle = str_replace("&", "", $imgTitle); $imgTitle = str_replace("'", "", $imgTitle); $imgTitle = @ereg_replace("[^A-Za-z0-9]", " ", $imgTitle); $imgTitle = preg_replace("/\\s+/", " ", $imgTitle); $imgTitle = str_replace(" ", "-", $imgTitle); $filename = $imgTitle . '.' . $ext; $image_name = $filename; echo "<img src='" . $uploaddir . $image_name . "' class='imgList'>"; $newname = $uploaddir . $image_name; if (move_uploaded_file($_FILES['photos']['tmp_name'][$name], $newname)) { $time = time(); $this->watermarkimages($uploaddir, $image_name); $timeImg = time(); @copy($filename, './server/php/rental/mobile/' . $filename); $target_file = $uploaddir . $image_name; $imageName = $filename; $option = $this->getImageShape(500, 350, $target_file); $renameArr = explode('.', $imageName); $newName = $renameArr[0] . '.jpg'; $resizeObj = new Resizeimage($target_file); $resizeObj->resizeImage(500, 350, $option); $resizeObj->saveImage($uploaddir . 'mobile/' . $newName, 100); $this->ImageCompress($uploaddir . 'mobile/' . $newName); @copy($uploaddir . 'mobile/' . $newName, $uploaddir . 'mobile/' . $newName); mysql_query("INSERT INTO fc_rental_photos(product_image,product_id) VALUES('{$image_name}','{$prd_id}')"); } else { echo '<span class="imgList">You have exceeded the size limit! so moving unsuccessful! </span>'; } } else { echo '<span class="imgList">You have exceeded the size limit!</span>'; } } else { echo "<script> alert('invalid')</script>"; } } else { echo "<script>alert('Please Choose High Resolution image'); window.location = 'photos_listing/.{$prd_id}';</script>"; } } } }