/** * Enter description here... * * @param String $destino * @param GLOBAL $file * @return $_FILES */ public static function upload($destino, $file, $nome = null) { ini_set('post_max_size', '8M'); ini_set('upload_max_filesize', '8M'); $arquivoTmp = $file["tmp_name"]; $file = $file["name"]; $file = @ereg_replace("[ÁÀÂÃ]", "A", $file); $file = @ereg_replace("[áàâãª]", "a", $file); $file = @ereg_replace("[ÉÈÊ]", "E", $file); $file = @ereg_replace("[éèê]", "e", $file); $file = @ereg_replace("[ÍÌÊ]", "I", $file); $file = @ereg_replace("[íìî]", "i", $file); $file = @ereg_replace("[ÓÒÔÕ]", "O", $file); $file = @ereg_replace("[óòôõº]", "o", $file); $file = @ereg_replace("[ÚÙÛ]", "U", $file); $file = @ereg_replace("[úùû]", "u", $file); $file = @str_replace("Ç", "C", $file); $file = @str_replace("ç", "c", $file); $file = @str_replace("-", "", $file); $file = @str_replace("'", "", $file); $file = @str_replace('"', '', $file); $file = @str_replace('_', '', $file); if (!empty($nome)) { $nomeArquivo = $nome; $arquivo = $destino . $nome; } else { $nomeArquivo = date('Ymd') . time() . str_replace(" ", "", $file); $arquivo = $destino . date('Ymd') . time() . str_replace(" ", "", $file); } if (!move_uploaded_file($arquivoTmp, $arquivo)) { $retorno = false; } else { $retorno = true; } self::$name_file = $nomeArquivo; return $retorno; }
$params = UploadFileCURL::getParamsPostUrl($_POST['data']); $remote_file = $_FILES['file']; if (!empty($params['path_img_thumb']) && !empty($params['path_img_larger'])) { $path_img_larger = $params['system'] . '/' . $params['path_img_larger']; UploadFileCURL::CreatePathPermission($path_img_larger); $path_img_thumb = $params['system'] . '/' . $params['path_img_thumb']; UploadFileCURL::CreatePathPermission($path_img_thumb); } elseif (!empty($params['path'])) { $path = $params['system'] . '/' . $params['path']; UploadFileCURL::CreatePathPermission($path); } foreach ($remote_file['name'] as $key => $value) { $file = array('name' => $value, 'type' => $remote_file['type'][$key], 'tmp_name' => $remote_file['tmp_name'][$key], 'error' => $remote_file['error'][$key], 'size' => $remote_file['size'][$key]); if ($remote_file['type'][$key] == 'image/jpeg' || $remote_file['type'][$key] == 'image/png') { UploadFileCURL::upload($path_img_larger, $file); $img_larger = $path_img_larger . UploadFileCURL::getNameFile(); $img_thumb = $path_img_thumb . UploadFileCURL::getNameFile(); $params['file'][] = array('img_larger' => $img_larger, 'img_thumb' => $img_thumb); if (!empty($params['thumb_width']) && !empty($params['thumb_heigth'])) { $simpleImage = new SimpleImage(); $simpleImage->load($img_larger); $simpleImage->resize($params['thumb_width'], $params['thumb_heigth']); $simpleImage->save($img_thumb); } } else { UploadFileCURL::upload($path, $file); $file_path = $path . UploadFileCURL::getNameFile(); $params['file'][] = array('file_path' => $file_path); } } echo json_encode($params);