本文整理汇总了PHP中move_uploaded_file函数的典型用法代码示例。如果您正苦于以下问题:PHP move_uploaded_file函数的具体用法?PHP move_uploaded_file怎么用?PHP move_uploaded_file使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了move_uploaded_file函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
/**
* Save an uploaded file to a new location.
*
* @param mixed name of $_FILE input or array of upload data
* @param string new filename
* @param string new directory
* @param integer chmod mask
* @return string full path to new file
*/
public static function save($file, $filename = NULL, $directory = NULL, $chmod = 0755)
{
// Load file data from FILES if not passed as array
$file = is_array($file) ? $file : $_FILES[$file];
if ($filename === NULL) {
// Use the default filename, with a timestamp pre-pended
$filename = time() . $file['name'];
}
// Remove spaces from the filename
$filename = preg_replace('/\\s+/', '_', $filename);
if ($directory === NULL) {
// Use the pre-configured upload directory
$directory = WWW_ROOT . 'files/';
}
// Make sure the directory ends with a slash
$directory = rtrim($directory, '/') . '/';
if (!is_dir($directory)) {
// Create the upload directory
mkdir($directory, 0777, TRUE);
}
//if ( ! is_writable($directory))
//throw new exception;
if (is_uploaded_file($file['tmp_name']) and move_uploaded_file($file['tmp_name'], $filename = $directory . $filename)) {
if ($chmod !== FALSE) {
// Set permissions on filename
chmod($filename, $chmod);
}
//$all_file_name = array(FILE_INFO => $filename);
// Return new file path
return $filename;
}
return FALSE;
}
示例2: upload
/**
* Upload component
*
* @requires component package file,
*
* @return bool;
*/
public function upload()
{
$archive = new ZipArchive();
$data_dir = ossn_get_userdata('tmp/components');
if (!is_dir($data_dir)) {
mkdir($data_dir, 0755, true);
}
$zip = $_FILES['com_file'];
$newfile = "{$data_dir}/{$zip['name']}";
if (move_uploaded_file($zip['tmp_name'], $newfile)) {
if ($archive->open($newfile) === TRUE) {
$archive->extractTo($data_dir);
//make community components works on installer #394
$validate = $archive->statIndex(0);
$validate = str_replace('/', '', $validate['name']);
$archive->close();
if (is_dir("{$data_dir}/{$validate}") && is_file("{$data_dir}/{$validate}/ossn_com.php") && is_file("{$data_dir}/{$validate}/ossn_com.xml")) {
$archive->open($newfile);
$archive->extractTo(ossn_route()->com);
$archive->close();
$this->newCom($validate);
OssnFile::DeleteDir($data_dir);
return true;
}
}
}
return false;
}
示例3: getUrlUploadMultiImages
public static function getUrlUploadMultiImages($obj, $user_id)
{
$url_arr = array();
$min_size = 1024 * 1000 * 700;
$max_size = 1024 * 1000 * 1000 * 3.5;
foreach ($obj["tmp_name"] as $key => $tmp_name) {
$ext_arr = array('png', 'jpg', 'jpeg', 'bmp');
$name = StringHelper::filterString($obj['name'][$key]);
$storeFolder = Yii::getPathOfAlias('webroot') . '/images/' . date('Y-m-d', time()) . '/' . $user_id . '/';
$pathUrl = 'images/' . date('Y-m-d', time()) . '/' . $user_id . '/' . time() . $name;
if (!file_exists($storeFolder)) {
mkdir($storeFolder, 0777, true);
}
$tempFile = $obj['tmp_name'][$key];
$targetFile = $storeFolder . time() . $name;
$ext = strtolower(pathinfo($name, PATHINFO_EXTENSION));
$size = $obj['name']['size'];
if (in_array($ext, $ext_arr)) {
if ($size >= $min_size && $size <= $max_size) {
if (move_uploaded_file($tempFile, $targetFile)) {
array_push($url_arr, $pathUrl);
} else {
return NULL;
}
} else {
return NULL;
}
} else {
return NULL;
}
}
return $url_arr;
}
示例4: addnew
function addnew()
{
if ($_POST) {
$image = $_FILES['logo'];
$image_name = $image['name'];
$image_tmp = $image['tmp_name'];
$image_size = $image['size'];
$error = $image['error'];
$file_ext = explode('.', $image_name);
$file_ext = strtolower(end($file_ext));
$allowed_ext = array('jpg', 'jpeg', 'bmp', 'png', 'gif');
$file_on_server = '';
if (in_array($file_ext, $allowed_ext)) {
if ($error === 0) {
if ($image_size < 3145728) {
$file_on_server = uniqid() . '.' . $file_ext;
$destination = './brand_img/' . $file_on_server;
move_uploaded_file($image_tmp, $destination);
}
}
}
$values = array('name' => $this->input->post('name'), 'description' => $this->input->post('desc'), 'logo' => $file_on_server, 'is_active' => 1);
if ($this->brand->create($values)) {
$this->session->set_flashdata('message', 'New Brand added successfully');
} else {
$this->session->set_flashdata('errormessage', 'Oops! Something went wrong!!');
}
redirect(base_url() . 'brands/');
}
$this->load->helper('form');
$this->load->view('includes/header', array('title' => 'Add Brand'));
$this->load->view('brand/new_brand');
$this->load->view('includes/footer');
}
示例5: save
function save($overwrite = true)
{
global $messageStack;
if (!$overwrite and file_exists($this->destination . $this->filename)) {
$messageStack->add_session(TEXT_IMAGE_OVERWRITE_WARNING . $this->filename, 'caution');
return true;
} else {
if (substr($this->destination, -1) != '/') {
$this->destination .= '/';
}
if (move_uploaded_file($this->file['tmp_name'], $this->destination . $this->filename)) {
chmod($this->destination . $this->filename, $this->permissions);
if ($this->message_location == 'direct') {
$messageStack->add(sprintf(SUCCESS_FILE_SAVED_SUCCESSFULLY, $this->filename), 'success');
} else {
$messageStack->add_session(sprintf(SUCCESS_FILE_SAVED_SUCCESSFULLY, $this->filename), 'success');
}
return true;
} else {
if ($this->message_location == 'direct') {
$messageStack->add(ERROR_FILE_NOT_SAVED, 'error');
} else {
$messageStack->add_session(ERROR_FILE_NOT_SAVED, 'error');
}
return false;
}
}
}
示例6: UploadImage
function UploadImage($bukti_name)
{
//direktori gambar
$vdir_upload = "bukti/";
$vfile_upload = $vdir_upload . $bukti_name;
//Simpan gambar dalam ukuran sebenarnya
move_uploaded_file($_FILES["bukti"]["tmp_name"], $vfile_upload);
//identitas file asli
$im_src = imagecreatefromjpeg($vfile_upload);
$src_width = imageSX($im_src);
$src_height = imageSY($im_src);
//Simpan dalam versi small 110 pixel
//Set ukuran gambar hasil perubahan
$dst_width = 50;
$dst_height = $dst_width / $src_width * $src_height;
//proses perubahan ukuran
$im = imagecreatetruecolor($dst_width, $dst_height);
imagecopyresampled($im, $im_src, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
//Simpan gambar
imagejpeg($im, $vdir_upload . "small_" . $bukti_name);
//Simpan dalam versi medium 360 pixel
//Set ukuran gambar hasil perubahan
$dst_width2 = 270;
$dst_height2 = $dst_width2 / $src_width * $src_height;
//proses perubahan ukuran
$im2 = imagecreatetruecolor($dst_width2, $dst_height2);
imagecopyresampled($im2, $im_src, 0, 0, 0, 0, $dst_width2, $dst_height2, $src_width, $src_height);
//Simpan gambar
imagejpeg($im2, $vdir_upload . "medium_" . $bukti_name);
//Hapus gambar di memori komputer
imagedestroy($im_src);
imagedestroy($im);
imagedestroy($im2);
}
示例7: uploadFilePost
/**
* POST: /file-tiny-mce/upload-file
*/
public function uploadFilePost()
{
$path = $_REQUEST['Path'];
$uploadFile = $_SERVER['DOCUMENT_ROOT'] . Config::$SUB_FOLDER . '/' . $path . basename($_FILES['File']['name']);
move_uploaded_file($_FILES['File']['tmp_name'], $uploadFile);
parent::redirectToUrlFromAction('file-tiny-mce', 'index', $path == '' ? '' : substr($path, 0, -1));
}
示例8: yukle
public function yukle($dosya)
{
$this->dosya = $dosya;
if (isset($this->dosya['name']) && empty($this->dosya['name'])) {
return $this->mesaj('Lütfen Yüklenecek Resmi Seçiniz.');
} else {
if ($this->dosya['size'] > $this->limit * 1024) {
return $this->mesaj('Resim Yükleme Limitini Aştınız.! MAX: ' . $this->limit . 'KB Yükleyebilirsiniz.');
} else {
if ($this->dosya['type'] == "image/gif" || $this->dosya['type'] == "image/pjpeg" || $this->dosya['type'] == "image/jpeg" || $this->dosya['type'] == "image/png") {
$yeni = time() . substr(md5(mt_rand(9, 999)), 8, 4);
$file = $this->dosya['name'];
$dosya_yolu = $this->buyuk . "/" . basename($yeni . substr($file, strrpos($file, ".")));
if (@move_uploaded_file($this->dosya['tmp_name'], $dosya_yolu)) {
$resim = $yeni . substr($file, strrpos($file, "."));
@chmod("./" . $dosya_yolu . $resim, 0644);
$this->createthumb($this->buyuk . $resim, $this->kucuk . $resim, $this->boyut, $this->boyut);
return $this->mesaj($this->succes, $resim, 1);
}
} else {
return $this->mesaj('Yanlış Bir Format Yüklemeye Çalıştınız. Format : JPG - GIF - PNG');
}
}
}
}
示例9: setFile
private function setFile($file)
{
$errorCode = $file['error'];
if ($errorCode === UPLOAD_ERR_OK) {
$type = exif_imagetype($file['tmp_name']);
if ($type) {
$extension = image_type_to_extension($type);
$src = 'img/' . date('YmdHis') . '.original' . $extension;
if ($type == IMAGETYPE_GIF || $type == IMAGETYPE_JPEG || $type == IMAGETYPE_PNG) {
if (file_exists($src)) {
unlink($src);
}
$result = move_uploaded_file($file['tmp_name'], $src);
if ($result) {
$this->src = $src;
$this->type = $type;
$this->extension = $extension;
$this->setDst();
} else {
$this->msg = 'Failed to save file';
}
} else {
$this->msg = 'Please upload image with the following types: JPG, PNG, GIF';
}
} else {
$this->msg = 'Please upload image file';
}
} else {
$this->msg = $this->codeToMessage($errorCode);
}
}
示例10: upload_pro
function upload_pro()
{
global $con;
if (isset($_POST['upload'])) {
$title = secure_code($_POST['title']);
$name = secure_code($_POST['name']);
$price = $_POST['price'];
$keywords = $_POST['keywords'];
$cat = secure_code($_POST['cat']);
$imag_name = $_FILES['img']['name'];
$imag_temp = $_FILES['img']['tmp_name'];
$store_images = 'product_images/';
$discription = secure_code($_POST['des']);
if ($title == '' || $name == '' || $price == '' || $keywords == '' || $cat == '' || $imag_name == '' || $discription == '') {
echo "<div class='alert alert-danger'><strong>Error</strong>: Please fill out the fields!</div>";
} else {
move_uploaded_file($imag_temp, $store_images . $imag_name);
$upload_query = mysqli_query($con, "INSERT INTO products (title,name,price,keywords,category,image,discription) VALUES ('{$title}','{$name}','{$price}','{$keywords}','{$cat}','{$imag_name}','{$discription}')");
if ($upload_query) {
echo "<div class='alert alert-success'><strong>Congratulation</strong> Product Successfully uploaded!</div>";
} else {
echo "<div class='alert alert-danger'>Sorry product not uplaod!</div>";
}
}
}
}
示例11: executeUpload
public function executeUpload(sfWebRequest $request)
{
$language = LanguageTable::getInstance()->find($request->getParameter('id'));
/* @var $language Language */
if (!$language) {
return $this->notFound();
}
if ($request->getPostParameter('csrf_token') == UtilCSRF::gen('language_upload', $language->getId())) {
$this->ajax()->setAlertTarget('#upload', 'append');
$file = $request->getFiles('file');
if ($file && $file['tmp_name']) {
$parser = new sfMessageSource_XLIFF();
if ($parser->loadData($file['tmp_name'])) {
$dir = dirname($language->i18nFileWidget());
if (!file_exists($dir)) {
mkdir($dir);
}
move_uploaded_file($file['tmp_name'], $language->i18nFileWidget());
$language->i18nCacheWidgetClear();
return $this->ajax()->alert('Language file updated.', '', null, null, false, 'success')->render(true);
}
return $this->ajax()->alert('File invalid.', '', null, null, false, 'error')->render(true);
}
return $this->ajax()->alert('Upload failed.', '', null, null, false, 'error')->render(true);
}
return $this->notFound();
}
示例12: insertarExcel
function insertarExcel($array)
{
$uploadOk = 1;
$time = time();
$fecha = date("Y-m-d", $time);
$target_dir = "../documents/";
$target_file = $target_dir . basename($_FILES["archivoExcel"]["name"]);
move_uploaded_file($array["archivoExcel"]["tmp_name"], $target_file);
set_include_path(get_include_path() . PATH_SEPARATOR . '../complements/PHPExcel-1.8/Classes/');
$inputFileType = 'Excel2007';
include 'PHPExcel/IOFactory.php';
$inputFileName = $target_file;
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load($inputFileName);
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
require_once "../db/conexiones.php";
$consulta = new Conexion();
foreach ($sheetData as $datos) {
$nombreSinAcentos = sanear_string($datos['B']);
$nombre = strtoupper(trim($nombreSinAcentos));
$datosEmpleado = $consulta->Conectar("postgres", "SELECT * FROM userinfo WHERE UPPER(name)='" . $nombre . "'");
if ($datosEmpleado) {
$sqlInsert = $this->invoco->Conectar("postgres", "INSERT INTO horario_personal (user_id, banda_id, fecha) VALUES (" . $datosEmpleado[0]['userid'] . "," . $datos['C'] . ", '" . $fecha . "')");
}
}
return "Se insertaron los datos Exitosamente!";
}
示例13: createnewpicture
private function createnewpicture()
{
$local = $this->path_two . $this->file['name'];
move_uploaded_file($this->file['tmp_name'], $local);
$filename = $this->file['tmp_name'] . "/" . $this->file['name'];
$this->location = $this->path . "/" . $this->file['name'];
switch ($this->file['type']) {
case 'image/jpeg':
$src = imagecreatefromjpeg($local);
break;
case 'image/png':
$src = imagecreatefrompng($local);
break;
case 'image/gif':
$src = imagecreatefromgif($local);
break;
default:
break;
}
$sx = imagesx($src);
$sy = imagesy($src);
$new_image = imagecreatetruecolor($this->newwidth, $this->newheight);
if (imagecopyresized($new_image, $src, 0, 0, 0, 0, $this->newwidth, $this->newheight, $sx, $sy)) {
if (ImageJpeg($new_image, $this->location) || Imagegif($new_image, $this->location) || Imagepng($new_image, $this->location)) {
//imagejpeg($this->location);
return true;
}
} else {
return false;
}
}
示例14: upload_originales
function upload_originales($fichier, $destination, $ext)
{
$sortie = array();
// récupération du nom d'origine
$nom_origine = $fichier['name'];
// récupération de l'extension du fichier mise en minuscule et sans le .
$extension_origine = substr(strtolower(strrchr($nom_origine, '.')), 1);
// si l'extension ne se trouve pas (!) dans le tableau contenant les extensions autorisées
if (!in_array($extension_origine, $ext)) {
// envoi d'une erreur et arrêt de la fonction
return "Erreur : Extension non autorisée";
}
// si l'extension est valide mais de type jpeg
if ($extension_origine === "jpeg") {
$extension_origine = "jpg";
}
// création du nom final (appel de la fonction chaine_hasard, pour la chaine de caractère aléatoire)
$nom_final = chaine_hasard(25);
// on a besoin du nom final dans le tableau $sortie si la fonction réussit
$sortie['poids'] = filesize($fichier['tmp_name']);
$sortie['largeur'] = getimagesize($fichier['tmp_name'])[0];
$sortie['hauteur'] = getimagesize($fichier['tmp_name'])[1];
$sortie['nom'] = $nom_final;
$sortie['extension'] = $extension_origine;
// on déplace l'image du dossier temporaire vers le dossier 'originales' avec le nom de fichier complet
if (@move_uploaded_file($fichier['tmp_name'], $destination . $nom_final . "." . $extension_origine)) {
return $sortie;
// si erreur
} else {
return "Erreur lors de l'upload d'image";
}
}
示例15: handleUpload
/**
* Handles an uploaded file, stores it to the correct folder, adds an entry
* to the database and returns a TBGFile object
*
* @param string $thefile The request parameter the file was sent as
*
* @return TBGFile The TBGFile object
*/
public function handleUpload($key, $file_name = null, $file_dir = null)
{
$apc_exists = self::CanGetUploadStatus();
if ($apc_exists && !array_key_exists($this->getParameter('APC_UPLOAD_PROGRESS'), $_SESSION['__upload_status'])) {
$_SESSION['__upload_status'][$this->getParameter('APC_UPLOAD_PROGRESS')] = array('id' => $this->getParameter('APC_UPLOAD_PROGRESS'), 'finished' => false, 'percent' => 0, 'total' => 0, 'complete' => 0);
}
try {
$thefile = $this->getUploadedFile($key);
if ($thefile !== null) {
if ($thefile['error'] == UPLOAD_ERR_OK) {
Logging::log('No upload errors');
if (is_uploaded_file($thefile['tmp_name'])) {
Logging::log('Uploaded file is uploaded');
$files_dir = $file_dir === null ? Caspar::getUploadPath() : $file_dir;
$new_filename = $file_name === null ? Caspar::getUser()->getID() . '_' . NOW . '_' . basename($thefile['name']) : $file_name;
Logging::log('Moving uploaded file to ' . $new_filename);
if (!move_uploaded_file($thefile['tmp_name'], $files_dir . $new_filename)) {
Logging::log('Moving uploaded file failed!');
throw new \Exception(Caspar::getI18n()->__('An error occured when saving the file'));
} else {
Logging::log('Upload complete and ok');
return true;
}
} else {
Logging::log('Uploaded file was not uploaded correctly');
throw new \Exception(Caspar::getI18n()->__('The file was not uploaded correctly'));
}
} else {
Logging::log('Upload error: ' . $thefile['error']);
switch ($thefile['error']) {
case UPLOAD_ERR_INI_SIZE:
case UPLOAD_ERR_FORM_SIZE:
throw new \Exception(Caspar::getI18n()->__('You cannot upload files bigger than %max_size% MB', array('%max_size%' => Settings::getUploadsMaxSize())));
break;
case UPLOAD_ERR_PARTIAL:
throw new \Exception(Caspar::getI18n()->__('The upload was interrupted, please try again'));
break;
case UPLOAD_ERR_NO_FILE:
throw new \Exception(Caspar::getI18n()->__('No file was uploaded'));
break;
default:
throw new \Exception(Caspar::getI18n()->__('An unhandled error occured') . ': ' . $thefile['error']);
break;
}
}
Logging::log('Uploaded file could not be uploaded');
throw new \Exception(Caspar::getI18n()->__('The file could not be uploaded'));
}
Logging::log('Could not find uploaded file' . $key);
throw new \Exception(Caspar::getI18n()->__('Could not find the uploaded file. Please make sure that it is not too big.'));
} catch (Exception $e) {
Logging::log('Upload exception: ' . $e->getMessage());
if ($apc_exists) {
$_SESSION['__upload_status'][$this->getParameter('APC_UPLOAD_PROGRESS')]['error'] = $e->getMessage();
$_SESSION['__upload_status'][$this->getParameter('APC_UPLOAD_PROGRESS')]['finished'] = true;
$_SESSION['__upload_status'][$this->getParameter('APC_UPLOAD_PROGRESS')]['percent'] = 100;
}
throw $e;
}
}