public function actionUpload() { if (isset($_FILES['files']) && $_FILES['files']) { require Yii::app()->basePath . '/components/upload.class.php'; $handle = new upload($_FILES['files']); $img_arr = array(); $file_info = AFunction::generate_file_name('news'); $_filename = $file_info['name']; $_filepath = realpath(Yii::app()->getBasePath() . '/../uploads/') . "/" . $file_info['physical_path']; if ($handle->uploaded) { //check extension if (!in_array($handle->file_src_name_ext, array('gif', 'jpg', 'jpeg', 'pjpeg'))) { //$this->error->add('ERROR_UPLOAD', $this->language->getMsg('YOU_CAN_UPLOAD_WITH_FILE_EXTENSION_JPG_JPEG_PJPEG')); return false; } $handle->file_new_name_body = $_filename; $handle->process($_filepath); if ($handle->processed) { require Yii::app()->basePath . '/components/byte_converter.class.php'; $byte = new byte_converter(); $byte->set_limit("mb"); $img_arr['id'] = 0; $img_arr['image_title'] = $_filename; $img_arr['image_ext'] = $handle->file_src_name_ext; $img_arr['image_path'] = $file_info['physical_path']; $img_arr['image_mime_type'] = $handle->image_src_type; $img_arr['image_width'] = $handle->image_src_x; $img_arr['image_height'] = $handle->image_src_y; $img_arr['image_size'] = $handle->file_src_size; $modelImage = new AImages(); $modelImage->image_title = $img_arr['image_title']; $modelImage->image_ext = $img_arr['image_ext']; $modelImage->image_path = $img_arr['image_path']; $modelImage->image_mime_type = $img_arr['image_mime_type']; $modelImage->image_width = $img_arr['image_width']; $modelImage->image_height = $img_arr['image_height']; $modelImage->image_size = $img_arr['image_size']; if ($modelImage->save()) { $img_arr['id'] = $modelImage->id; } } //upload width thumbnail 110 $handle->file_new_name_body = $_filename . '_' . Yii::app()->params->width110; $handle->image_resize = true; $handle->image_x = Yii::app()->params->width110; $handle->image_ratio_y = true; $handle->process($_filepath); if ($handle->processed) { $handle->Clean(); } echo json_encode($img_arr); exit; } else { echo json_encode(array('Upload Fail !')); exit; } } else { echo json_encode(array('Can not upload file !')); exit; } }
</div> <div style="float: right"> <input type="button" id="cancel" name="cancel" value="{#cancel}" onclick="tinyMCEPopup.close();" /> </div> </div> </form> <?php include './classes/class.upload.php'; if (isset($_POST['action']) && $_POST['action'] == 'image') { include './config.php'; $handle = new upload($_FILES['image_field'], $language); include './config.php'; $handle->Process($server_image_directory); if ($handle->uploaded) { if ($handle->processed) { echo "<script>setTimeout(\"document.getElementById('src').value='" . $url_image_directory . "/" . $handle->file_dst_name . "'\", 200)</script>"; echo "<script>setTimeout(\"ImageDialog.showPreviewImage(document.getElementById('src').value)\", 400)</script>"; } else { $error_str = str_replace("'", "`", $handle->error); echo "<script>alert('{$error_str}')</script>"; } $handle->Clean(); } else { $error_str = str_replace("'", "`", $handle->error); echo "<script>alert('{$error_str}')</script>"; } } ?> </body> </html>
public static function downloadImage($url, $params) { $cacheTime = $params->get('feedcache', 60); $imgcheckmime = (int) $params->get('checkmime', 1); $url = str_replace(" ", "%20", JString::trim($url)); if (!$params->get('storeimages', 0) || !$cacheTime || JString::strlen($url) < 6 || JString::substr($url, 0, 4) != "http") { return $url; } $ext = JString::strtolower(end(explode('.', $url, 2))); if (empty($ext)) { $ext = 'jpg'; } $valid_ext = array('png', 'jpg', 'jpeg', 'gif', 'bmp', 'ico'); if ($imgcheckmime && !in_array($ext, $valid_ext)) { return $url; } $cachePath = JPATH_SITE . DS . 'cache' . DS . 'mod_we_ufeed_display'; $cacheTime = $cacheTime * 60; //to seconds $filename = JFile::makeSafe(md5($url) . "." . $ext); if (!JFolder::exists($cachePath)) { JFolder::create($cachePath); } if (JFile::exists($cachePath . DS . $filename)) { if (time() < filemtime($cachePath . DS . $filename) + $cacheTime && is_readable($cachePath . DS . $filename)) { return JString::trim(JURI::root(true) . '/cache/mod_we_ufeed_display/' . $filename); } else { JFile::delete($cachePath . DS . $filename); } } $buffer = ""; if (in_array('curl', get_loaded_extensions()) && !@ini_get('safe_mode')) { $ch = curl_init(); // cURL curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); $buffer = @curl_exec($ch); curl_close($ch); } elseif (empty($buffer) && @ini_get('allow_url_fopen')) { $buffer = @file_get_contents($url); } $img = $url; if (!empty($buffer) && JFile::write($cachePath . DS . $filename, $buffer) && filesize($cachePath . DS . $filename) > 999) { $img = JURI::root(true) . '/cache/mod_we_ufeed_display/' . $filename; $stored = true; } else { $img = $url; if (JFile::exists($cachePath . DS . $filename)) { JFile::delete($cachePath . DS . $filename); } } $allowResize = false; if ($allowResize && $stored && $cropImages) { if (!class_exists('upload')) { require_once dirname(__FILE__) . DS . 'resizer.php'; } $handle = new upload($cachePath . DS . $filename); $handle->image_resize = true; $handle->image_ratio_y = true; $handle->image_convert = 'jpg'; $handle->jpeg_quality = $params->get('imagesQuality', 100); $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $filename; $handle->image_x = $params->get('resizewidth', '150'); $handle->Process($cachePath); $handle->Clean(); } return $img; }
$file->file_new_name_body = "docCurso" . $id; $file->Process($r . '/public/uploads/'); if ($file->processed) { $ret['msg'] = "Upload Concluido"; $ret['id'] = $id; $model->setId($id); $model->setDocumentoAutorizacao($r . '/public/uploads/docCurso' . $id); $control->edit($model); } else { $ret['msg'] = $file->error; $ret['id'] = -1; $model->setId($id); $control->delete($model); } } $file->Clean(); print json_encode($ret); break; case 'getDoc': require_once "../classes/Upload.class.php"; $link = $_SERVER['DOCUMENT_ROOT'] . '/public/uploads/docCurso' . $id . '.pdf'; $file = new upload($link); header("Content-type: " . $file->file_src_mime); echo $file->Process(); break; // caso a ação seja de editar um Curso existente // caso a ação seja de editar um Curso existente case 'edit': // cria um controller de Curso $controlCurso = CursoController::getInstance(); // cria um modelo de Curso com valores existentes no banco