本文整理汇总了PHP中is_uploaded_file函数的典型用法代码示例。如果您正苦于以下问题:PHP is_uploaded_file函数的具体用法?PHP is_uploaded_file怎么用?PHP is_uploaded_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了is_uploaded_file函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _validate
protected function _validate($context)
{
$config = $this->_config;
$row = $context->caller;
if (is_uploaded_file($row->file) && $config->restrict && !in_array($row->extension, $config->ignored_extensions->toArray()))
{
if ($row->isImage())
{
if (getimagesize($row->file) === false) {
$context->setError(JText::_('WARNINVALIDIMG'));
return false;
}
}
else
{
$mime = KFactory::get('com://admin/files.database.row.file')->setData(array('path' => $row->file))->mimetype;
if ($config->check_mime && $mime)
{
if (in_array($mime, $config->illegal_mimetypes->toArray()) || !in_array($mime, $config->allowed_mimetypes->toArray())) {
$context->setError(JText::_('WARNINVALIDMIME'));
return false;
}
}
elseif (!$config->authorized) {
$context->setError(JText::_('WARNNOTADMIN'));
return false;
}
}
}
}
示例2: postProcess
public function postProcess()
{
if (Tools::isSubmit('submitAdd' . $this->table)) {
if ($id = intval(Tools::getValue('id_attachment')) and $a = new Attachment($id)) {
$_POST['file'] = $a->file;
$_POST['mime'] = $a->mime;
}
if (!sizeof($this->_errors)) {
if (isset($_FILES['file']) and is_uploaded_file($_FILES['file']['tmp_name'])) {
if ($_FILES['file']['size'] > $this->maxFileSize) {
$this->_errors[] = $this->l('File too large, maximum size allowed:') . ' ' . $this->maxFileSize / 1000 . ' ' . $this->l('kb');
} else {
$uploadDir = dirname(__FILE__) . '/../../download/';
do {
$uniqid = sha1(microtime());
} while (file_exists($uploadDir . $uniqid));
if (!copy($_FILES['file']['tmp_name'], $uploadDir . $uniqid)) {
$this->_errors[] = $this->l('File copy failed');
}
@unlink($_FILES['file']['tmp_name']);
$_POST['name_2'] .= '.' . pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
$_POST['file'] = $uniqid;
$_POST['mime'] = $_FILES['file']['type'];
}
}
}
$this->validateRules();
}
return parent::postProcess();
}
示例3: upload_file
function upload_file()
{
echo "hi";
$FromUserId = $_POST['FromUserId'];
// $upload_dir = 'C:\Users\Kumi\Desktop\phpUpload';
echo $FromUserId;
echo "hello0";
$upload_dir = '/afs/cad/u/h/h/hhm4/public_html/UPLOADS/';
$upload_dir_db = 'C:\\\\Users\\\\Kumi\\\\Desktop\\\\phpUpload';
echo "hello1";
print_r($_FILES);
if (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
echo "hello2";
$dest = $_FILES['userfile']['name'];
print_r($_FILES);
echo $dest;
echo $upload_dir / $dest;
$dest_db = "\\\\" . $dest;
$store_dir = $upload_dir_db . $dest_db;
echo "{$store_dir}";
$moveBool = false;
$moveBool = move_uploaded_file($_FILES['userfile']['tmp_name'], "{$upload_dir}/{$dest}");
if ($moveBool) {
print_r('Success');
}
} else {
echo "Possible file upload attack: ";
echo "filename '" . $_FILES['userfile']['tmp_name'] . "'.";
print_r($_FILES);
}
}
示例4: upload
function upload($filename)
{
$log = '../log/error.log';
// print_r($_FILES);
// exit();
echo '<br>FILE NAME ->' . $_FILES['type'] . "<br>";
if (preg_match('/^image\\/p?jpeg$/i', $_FILES['upload']['type'])) {
$ext = '.jpg';
} else {
if (preg_match('/^image\\/gif$/i', $_FILES['upload']['type'])) {
$ext = '.gif';
} else {
if (preg_match('/^image\\/(x-)?png$/i', $_FILES['upload']['type'])) {
$ext = '.png';
} else {
$ext = '.unknown';
}
}
}
$filename = '/img/' . time() . $filename . $_SERVER['REMOTE_ADDR'] . $ext;
if (!is_uploaded_file($_FILES['upload']['tmp_name']) or !copy($_FILES['upload']['tmp_name'], $filename)) {
$error = PHP_EOL . time() . "\t" . $_SERVER['REMOTE_ADDR'] . "-\tCould not save file as {$filename}!";
file_put_contents($log, $error, FILE_APPEND);
}
return $filename;
}
示例5: 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;
}
}
示例6: getUploadedFilePath
/**
* Return the (temporary) path to an uploaded file.
* @param $fileName string the name of the file used in the POST form
* @return string (boolean false if no such file)
*/
function getUploadedFilePath($fileName)
{
if (isset($_FILES[$fileName]['tmp_name']) && is_uploaded_file($_FILES[$fileName]['tmp_name'])) {
return $_FILES[$fileName]['tmp_name'];
}
return false;
}
示例7: send
public function send($data, $name, $local)
{
if (!empty($data)) {
//echo 'component: <pre>'; print_r ($data); echo '</pre>';
//echo '<br>'.count($data);
//exit;
/*if ( count( $data ) > $this->max_files ) {
throw new InternalErrorException("Error Processing Request. Max number files accepted is {$this->max_files}", 1);
}*/
$file = $data;
//foreach ($data as $file) {
//echo 'component file: <pre>'; print_r ($file); echo '</pre>';
//echo '<br>'.count($data);
//exit;
$filename = $file['name'];
$file_tmp_name = $file['tmp_name'];
$dir = WWW_ROOT . 'uploads' . DS . $local;
$allowed = array('png', 'jpg', 'jpeg', 'pdf', 'doc', 'docx', 'txt', 'css', 'html');
if (!in_array(substr(strrchr($filename, '.'), 1), $allowed)) {
throw new InternalErrorException("Error Processing Request.", 1);
} elseif (is_uploaded_file($file_tmp_name)) {
//move_uploaded_file($file_tmp_name, $dir.DS.Text::uuid().'-'.$filename);
move_uploaded_file($file_tmp_name, $dir . DS . $name);
}
//}
//exit;
}
}
示例8: check
function check()
{
if (isset($_FILES[$this->ref])) {
$this->fileInfo = $_FILES[$this->ref];
} else {
$this->fileInfo = array('name' => '', 'type' => '', 'size' => 0, 'tmp_name' => '', 'error' => UPLOAD_ERR_NO_FILE);
}
if ($this->fileInfo['error'] == UPLOAD_ERR_NO_FILE) {
if ($this->required) {
return $this->container->errors[$this->ref] = jForms::ERRDATA_REQUIRED;
}
} else {
if ($this->fileInfo['error'] == UPLOAD_ERR_NO_TMP_DIR || $this->fileInfo['error'] == UPLOAD_ERR_CANT_WRITE) {
return $this->container->errors[$this->ref] = jForms::ERRDATA_FILE_UPLOAD_ERROR;
}
if ($this->fileInfo['error'] == UPLOAD_ERR_INI_SIZE || $this->fileInfo['error'] == UPLOAD_ERR_FORM_SIZE || $this->maxsize && $this->fileInfo['size'] > $this->maxsize) {
return $this->container->errors[$this->ref] = jForms::ERRDATA_INVALID_FILE_SIZE;
}
if ($this->fileInfo['error'] == UPLOAD_ERR_PARTIAL || !is_uploaded_file($this->fileInfo['tmp_name'])) {
return $this->container->errors[$this->ref] = jForms::ERRDATA_INVALID;
}
if (count($this->mimetype)) {
$this->fileInfo['type'] = \Jelix\FileUtilities\File::getMimeType($this->fileInfo['tmp_name']);
if ($this->fileInfo['type'] == 'application/octet-stream') {
// let's try with the name
$this->fileInfo['type'] = \Jelix\FileUtilities\File::getMimeTypeFromFilename($this->fileInfo['name']);
}
if (!in_array($this->fileInfo['type'], $this->mimetype)) {
return $this->container->errors[$this->ref] = jForms::ERRDATA_INVALID_FILE_TYPE;
}
}
}
return null;
}
示例9: downloadCsv
function downloadCsv()
{
/*Validating photo - checking if downloaded, size, type*/
if (isset($_FILES['csv_file'])) {
/*checking photo size*/
if ($_FILES["csv_file"]["size"] > 1024 * 1024) {
echo "<p>Слишком большой файл.</p>";
exit;
} elseif (validateFileType($_FILES["csv_file"]["type"]) == false) {
echo "Файл должен быть в формате CSV";
exit;
}
/*Checking/creating image folder*/
$dir = "download_to";
if (!is_dir($dir)) {
mkdir($dir);
}
/*checking if photo downloaded correctly*/
if (is_uploaded_file($_FILES["csv_file"]["tmp_name"])) {
if ($_FILES['csv_file']['error'] == 0) {
// Если файл загружен успешно, перемещаем его из временной директории в конечную
move_uploaded_file($_FILES["csv_file"]["tmp_name"], "download_to/" . $_FILES["csv_file"]["name"]);
$_FILES["csv_file"]["tmp_name"] = "/import-of-products/download_to/";
}
}
echo "CSV file downloaded successfully!<br>";
//var_dump($_FILES['csv_file']);
} else {
echo "Вы не выбрали файл.";
}
}
示例10: upload
function upload($to_name = "")
{
$new_name = $this->set_file_name($to_name);
if ($this->check_file_name($new_name)) {
if ($this->validateExtension()) {
if (is_uploaded_file($this->the_temp_file)) {
$this->file_copy = $new_name;
if ($this->move_upload($this->the_temp_file, $this->file_copy)) {
$this->message[] = $this->error_text($this->http_error);
if ($this->rename_file) {
$this->message[] = $this->error_text(16);
}
return true;
}
} else {
$this->message[] = $this->error_text($this->http_error);
return false;
}
} else {
$this->show_extensions();
$this->message[] = $this->error_text(11);
return false;
}
} else {
return false;
}
}
示例11: subirArchivo
function subirArchivo($arch, $folder, $filename, $extensionesPermitidas, $maxFileSize, &$error, &$finalFilename) {
$tmpfile = $arch["tmp_name"];
$partes_ruta = pathinfo(strtolower($arch["name"]));
if (!in_array($partes_ruta["extension"], $extensionesPermitidas)) {
$error = "El archivo debe tener alguna de las siguientes extensiones: ".implode(" o ", $extensionesPermitidas).".";
return false;
}
$filename = stringToLower($filename.".".$partes_ruta["extension"]);
$finalFilename = $folder.$filename;
if (!is_uploaded_file($tmpfile)) {
$error = "El archivo no subió correctamente.";
return false;
}
if (filesize($tmpfile) > $maxFileSize) {
$error = "El archivo no puede ser mayor a ".tamanoArchivo($maxFileSize).".";
return false;
}
if (!move_uploaded_file($tmpfile, $folder.$filename)) {
$error = "El archivo no pudo ser guardado.";
return false;
}
return true;
}
示例12: Uploadpic
/**
* 上传图片
*/
protected function Uploadpic($picdir = "")
{
$res['error'] = "";
if (is_uploaded_file($_FILES['fileToUpload']['tmp_name'])) {
$info = explode('.', strrev($_FILES['fileToUpload']['name']));
//配置要上传目录地址
$datadir = date("Y-m-d");
$picdir = $picdir . "/" . $datadir;
$picname = "user_" . intval($_REQUEST['project_id']) . "_" . time() . "." . strrev($info[0]);
$fullname = $picdir . "/" . $picname;
if (BaseTool::createABFolder($picdir)) {
if (move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $fullname)) {
$res["msg"] = "success";
$res["dir"] = $datadir . "/" . $picname;
} else {
$res["error"] = "上传失败";
}
} else {
$res['error'] = "上传失败";
}
} else {
$res['error'] = '上传的文件不存在';
}
return $res;
}
示例13: import_translations_post
function import_translations_post($project_path, $locale_slug, $translation_set_slug)
{
$project = GP::$project->by_path($project_path);
$locale = GP_Locales::by_slug($locale_slug);
if (!$project || !$locale) {
return $this->die_with_404();
}
$translation_set = GP::$translation_set->by_project_id_slug_and_locale($project->id, $translation_set_slug, $locale_slug);
if (!$translation_set) {
return $this->die_with_404();
}
if ($this->cannot_and_redirect('approve', 'translation-set', $translation_set->id)) {
return;
}
$format = gp_array_get(GP::$formats, gp_post('format', 'po'), null);
if (!$format) {
$this->redirect_with_error(__('No such format.', 'glotpress'));
return;
}
if (!is_uploaded_file($_FILES['import-file']['tmp_name'])) {
$this->redirect_with_error(__('Error uploading the file.', 'glotpress'));
return;
}
$translations = $format->read_translations_from_file($_FILES['import-file']['tmp_name'], $project);
if (!$translations) {
$this->redirect_with_error(__('Couldn’t load translations from file!', 'glotpress'));
return;
}
$translations_added = $translation_set->import($translations);
$this->notices[] = sprintf(__('%s translations were added', 'glotpress'), $translations_added);
$this->redirect(gp_url_project($project, gp_url_join($locale->slug, $translation_set->slug)));
}
示例14: saveFile
public static function saveFile($file, $form)
{
if (!is_uploaded_file($file['tmp_name'])) {
return $form;
}
$fileName = mediaUtils::fixFileName($file['name']);
$fileDir = dir::media($fileName);
$extension = substr(strrchr($fileName, '.'), 1);
// z.B. jpg
$badExtensions = dyn::get('addons')['badExtensions'];
// Wenn die Datei eine "verbotene" Datei ist
if (in_array($extension, $badExtensions)) {
$form->setSave(false);
$form->setErrorMessage(sprintf(lang::get('media_error_bad_extension'), $file['name']));
return $form;
}
if ($form->isEditMode()) {
$media = new media(type::super('id', 'int', 0));
}
// Wenn Datei nicht Existiert
// Oder man möchte sie überspeichern
if ($form->isEditMode() && $media->get('filename') != $fileName || !$form->isEditMode() && file_exists($fileDir)) {
$form->setSave(false);
$form->setErrorMessage(sprintf(lang::get('media_error_already_exist'), $file['name']));
return $form;
}
if (!move_uploaded_file($file['tmp_name'], $fileDir)) {
$form->setSave(false);
$form->setErrorMessage(sprintf(lang::get('media_error_move'), $file['name']));
return $form;
}
$form->addPost('filename', $fileName);
$form->addPost('size', filesize($fileDir));
return $form;
}
示例15: initialize
private function initialize($file, $path = NULL)
{
if (is_array($file)) {
// uploaded file
// check if file is realy uploaded
if (!array_key_exists('tmp_name', $file) || !is_uploaded_file($file['tmp_name'])) {
throw new Exception('wrong file.');
}
// first move uploaded file to safe (read safemode) location
$this->file = basename($file['tmp_name']);
/*
$director = Director::getInstance();
$tmpPath = $director->getTempPath();
move_uploaded_file($file['tmp_name'], $tmpPath."/".$this->file);
*/
$this->setPath(dirname($file['tmp_name']));
$this->filename = $file['name'];
$this->uploaded = true;
} else {
// file from database or whatever
$this->setPath(isset($path) ? realpath($path) : realpath(dirname($file)));
$this->file = basename($file);
$this->filename = $this->file;
$this->uploaded = false;
// check if file exists
if (!is_file($this->getFileName())) {
$this->file = '';
}
}
// check if file is image
//if(!$this->isImage($this->filename)) throw new Exception("file type not supported: {$this->filename}");
if (!$this->isImage($this->filename)) {
$this->file = '';
}
}