本文整理汇总了PHP中Upload::upload_file方法的典型用法代码示例。如果您正苦于以下问题:PHP Upload::upload_file方法的具体用法?PHP Upload::upload_file怎么用?PHP Upload::upload_file使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Upload
的用法示例。
在下文中一共展示了Upload::upload_file方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: share_validation
public function share_validation()
{
$this->load->library('form_validation');
$this->load->helper('form');
$this->form_validation->set_error_delimiters('<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">×</button>', '</div>');
//mise en place des regles
$this->form_validation->set_rules('keywords', 'Mots-clés', 'required|encode_php_tags|htmlspecialchars|trim|xss_clean|max_length[200]');
$this->form_validation->set_rules('description', 'Description', 'required|encode_php_tags|htmlspecialchars|trim|xss_clean|max_length[300]');
if ($this->form_validation->run() == FALSE) {
//on affiche le formulaire
$this->share();
} else {
// upload du fichier
$file_up = new Upload();
$user = unserialize($this->session->userdata('user_obj'));
if ($file_up->upload_file($user->id, array('userfile'))) {
// Création fichier
$file = new File();
$file->id_user = $user->id;
$file->desc = $this->input->post('description');
$file->keywords = $this->input->post('keywords');
$file->url = $file_up->files_uploaded[0][0];
$file->type = $file_up->files_uploaded[0][1];
//sauvegarde du fichier
$file->save();
//notification
$this->session->set_userdata('notif_ok', '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert">×</button><strong>Bravo! </strong> Votre partage a été réussi.</div>');
//redirection sur l'actualité
redirect('flux', 'refresh');
} else {
//on affiche le formulaire
$this->share();
}
}
}
示例2: __construct
<?php
header("Content-Type:text/html; charset=utf-8");
if ($_POST['submit']) {
$upFile = new Upload();
$upFile->upload_file();
}
class Upload
{
public $name;
public $tmp_name;
public $final_name;
public $target_dir;
public $target_path;
public $file_type;
public $allow_file_types;
public $file_size;
public $file_max_size;
/**
* __construct
*/
public function __construct()
{
$this->name = $_FILES["file"]["name"];
$this->file_type = $_FILES["file"]["type"];
$this->tmp_name = $_FILES["file"]["tmp_name"];
$this->allow_file_types = array('jpeg', 'doc', 'docx', 'dll', 'rar', 'zip', 'wps');
$this->file_size = $_FILES['file']['size'];
$this->target_dir = './Upload';
}
/**
示例3: ceil
//.........这里部分代码省略.........
$query = $DB->query("SELECT avatar_filename FROM exp_members WHERE member_id = '".$SESS->userdata('member_id')."'");
$old_filename = ($query->row['avatar_filename'] == '') ? '' : $query->row['avatar_filename'];
if (ereg('/', $old_filename))
{
$xy = explode('/', $old_filename);
$old_filename = end($xy);
}
}
elseif ($type == 'photo')
{
$query = $DB->query("SELECT photo_filename FROM exp_members WHERE member_id = '".$SESS->userdata('member_id')."'");
$old_filename = ($query->row['photo_filename'] == '') ? '' : $query->row['photo_filename'];
}
else
{
$query = $DB->query("SELECT sig_img_filename FROM exp_members WHERE member_id = '".$SESS->userdata('member_id')."'");
$old_filename = ($query->row['sig_img_filename'] == '') ? '' : $query->row['sig_img_filename'];
}
/** -------------------------------------
/** Upload the image
/** -------------------------------------*/
require PATH_CORE.'core.upload'.EXT;
$UP = new Upload();
$UP->new_name = $new_filename;
$UP->set_upload_path($upload_path);
$UP->set_allowed_types('img');
if ( ! $UP->upload_file())
{
@unlink($UP->new_name);
$info = ($UP->error_msg == 'invalid_filetype') ? "<div class='itempadbig'>".$LANG->line('invalid_image_type')."</div>" : '';
return $OUT->show_user_error('submission', $LANG->line($UP->error_msg).$info);
}
/** -------------------------------------
/** Do we need to resize?
/** -------------------------------------*/
$vals = @getimagesize($UP->new_name);
$width = $vals['0'];
$height = $vals['1'];
if ($width > $max_width OR $height > $max_height)
{
/** -------------------------------------
/** Was resizing successful?
/** -------------------------------------*/
// If not, we'll delete the uploaded image and
// issue an error saying the file is to big
if ( ! $this->_image_resize($new_filename, $type))
{
@unlink($UP->new_name);
$max_size = str_replace('%x', $max_width, $LANG->line('max_image_size'));
$max_size = str_replace('%y', $max_height, $max_size);
$max_size .= ' - '.$max_kb.'KB';
示例4: foreach
if (!empty($additional_image_fields)) {
foreach ($additional_image_fields as $key => $val) {
if (isset($HTTP_POST_VARS[$key]) && intval($val[2]) == 1 && trim($HTTP_POST_VARS[$key]) == "") {
$error = 1;
$field_error = preg_replace("/" . $site_template->start . "field_name" . $site_template->end . "/siU", str_replace(":", "", $val[0]), $lang['field_required']);
$msg .= ($msg != "" ? "<br />" : "") . $field_error;
}
}
}
if (!$error) {
// Start Upload
include ROOT_PATH . 'includes/upload.php';
$site_upload = new Upload();
// Upload Media file
if (!empty($HTTP_POST_FILES['media_file']['tmp_name']) && $HTTP_POST_FILES['media_file']['tmp_name'] != "none") {
$new_name = $site_upload->upload_file("media_file", "media", $upload_cat);
if (!$new_name) {
$msg .= ($msg != "" ? "<br />" : "") . "<b>" . $lang['file_upload_error'] . ": " . $new_name . "</b><br />" . $site_upload->get_upload_errors();
$uploaderror = 1;
}
} else {
$new_name = $remote_media_file;
}
// Upload thumb file
$new_thumb_name = "";
if (!empty($HTTP_POST_FILES['thumb_file']['tmp_name']) && $HTTP_POST_FILES['thumb_file']['tmp_name'] != "none" && !$uploaderror) {
$new_thumb_name = $site_upload->upload_file("thumb_file", "thumb", $upload_cat, get_basefile($new_name));
if (!$new_thumb_name) {
$msg .= ($msg != "" ? "<br />" : "") . "<b>" . $lang['thumb_upload_error'] . ": " . $new_thumb_name . "</b><br />" . $site_upload->get_upload_errors();
@unlink(MEDIA_TEMP_PATH . "/" . $new_name);
$uploaderror = 1;
示例5: count
/** ----------------------------------
/** Upload File
/** ----------------------------------*/
function upload_file()
{
global $IN, $DSP, $DB, $LANG, $SESS;
$id = $IN->GBL('destination');
$field_group = $IN->GBL('field_group');
$query = $DB->query("SELECT * FROM exp_upload_prefs WHERE id = '" . $DB->escape_str($id) . "'");
if ($query->num_rows == 0) {
return;
}
if ($SESS->userdata['group_id'] != 1) {
$safety = $DB->query("SELECT count(*) AS count FROM exp_upload_no_access WHERE upload_id = '" . $query->row['id'] . "' AND upload_loc = 'cp' AND member_group = '" . $SESS->userdata['group_id'] . "'");
if ($safety->row['count'] != 0) {
exit('no access');
return $DSP->no_access_message();
}
}
require PATH_CORE . 'core.upload' . EXT;
$UP = new Upload();
if ($UP->set_upload_path($query->row['server_path']) !== TRUE) {
return $UP->show_error();
}
$UP->set_max_width($query->row['max_width']);
$UP->set_max_height($query->row['max_height']);
$UP->set_max_filesize($query->row['max_size']);
$UP->set_allowed_types($SESS->userdata['group_id'] == 1 ? 'all' : $query->row['allowed_types']);
if (!$UP->upload_file()) {
return $UP->show_error();
}
global $UL;
$UL = $UP;
if ($UL->file_exists == TRUE) {
return $this->file_exists_warning();
}
$this->finalize_uploaded_file(array('id' => $id, 'field_group' => $field_group, 'file_name' => $UP->file_name, 'is_image' => $UP->is_image, 'step' => 1));
}
示例6: foreach
$error['remote_file'] = 1;
}
if ((empty($HTTP_POST_FILES['thumb_file']['tmp_name']) || $HTTP_POST_FILES['thumb_file']['tmp_name'] == "none") && $remote_thumb_file != "" && !check_remote_thumb($remote_thumb_file) && !check_local_thumb($remote_thumb_file)) {
$error['remote_thumb_file'] = 1;
}
if (!empty($additional_image_fields)) {
foreach ($additional_image_fields as $key => $val) {
if (isset($HTTP_POST_VARS[$key]) && intval($val[2]) == 1 && trim($HTTP_POST_VARS[$key]) == "") {
$error[$key] = 1;
}
}
}
if (!empty($HTTP_POST_FILES['file']['tmp_name']) && $HTTP_POST_FILES['file']['tmp_name'] != "none" && !$error) {
unset($HTTP_POST_VARS['remote_file']);
@rename(MEDIA_PATH . "/" . $old_cat_id . "/" . $old_file_name, MEDIA_PATH . "/" . $old_cat_id . "/" . $old_file_name . ".bak");
$new_name = $site_upload->upload_file("file", "media", $cat_id);
if (!$new_name) {
$error_msg .= $lang['file_upload_error'] . ": <b>" . $HTTP_POST_FILES['file']['name'] . "</b><br />" . $site_upload->get_upload_errors();
@rename(MEDIA_PATH . "/" . $old_cat_id . "/" . $old_file_name . ".bak", MEDIA_PATH . "/" . $old_cat_id . "/" . $old_file_name);
$error = 1;
} else {
unlink(MEDIA_PATH . "/" . $old_cat_id . "/" . $old_file_name . ".bak");
$log[] = $lang['file_upload_success'] . ": <b>{$new_name}</b>";
}
} elseif ((empty($HTTP_POST_FILES['file']['tmp_name']) || $HTTP_POST_FILES['file']['tmp_name'] == "none") && $remote_file != "" && (check_remote_media($remote_file) || check_local_media($remote_file))) {
$new_name = $remote_file;
if (file_exists(MEDIA_PATH . "/" . $old_cat_id . "/" . $old_file_name) && is_file(MEDIA_PATH . "/" . $old_cat_id . "/" . $old_file_name)) {
unlink(MEDIA_PATH . "/" . $old_cat_id . "/" . $old_file_name);
}
} else {
if ($cat_id != $old_cat_id && !empty($old_file_name)) {
示例7: foreach
$error['remote_file'] = 1;
}
if ((empty($HTTP_POST_FILES['thumb_file']['tmp_name']) || $HTTP_POST_FILES['thumb_file']['tmp_name'] == "none") && $remote_thumb_file != "" && !check_remote_thumb($remote_thumb_file) && !check_local_thumb($remote_thumb_file)) {
$error['remote_thumb_file'] = 1;
}
if (!empty($additional_image_fields)) {
foreach ($additional_image_fields as $key => $val) {
if (isset($HTTP_POST_VARS[$key]) && intval($val[2]) == 1 && trim($HTTP_POST_VARS[$key]) == "") {
$error[$key] = 1;
}
}
}
if (!empty($HTTP_POST_FILES['file']['tmp_name']) && $HTTP_POST_FILES['file']['tmp_name'] != "none" && !$error) {
unset($HTTP_POST_VARS['remote_file']);
@rename(MEDIA_TEMP_PATH . "/" . $old_file_name, MEDIA_TEMP_PATH . "/" . $old_file_name . ".bak");
$new_name = $site_upload->upload_file("file", "media", 0);
if (!$new_name) {
$error_msg .= $lang['file_upload_error'] . ": <b>" . $HTTP_POST_FILES['file']['name'] . "</b><br />" . $site_upload->get_upload_errors();
@rename(MEDIA_TEMP_PATH . "/" . $old_file_name . ".bak", MEDIA_TEMP_PATH . "/" . $old_file_name);
$error = 1;
} else {
$log[] = $lang['file_upload_success'] . ": <b>" . $new_name . "</b>";
}
} elseif ((empty($HTTP_POST_FILES['file']['tmp_name']) || $HTTP_POST_FILES['file']['tmp_name'] == "none") && $remote_file != "" && check_remote_media($remote_file)) {
$new_name = $remote_file;
if (file_exists(MEDIA_TEMP_PATH . "/" . $old_file_name)) {
unlink(MEDIA_TEMP_PATH . "/" . $old_file_name);
}
} else {
$new_name = $old_file_name;
}
示例8: Upload
<?php
header('Content-type: text/html; charset=UTF-8');
require './Upload.php';
$upload = new Upload($_FILES['arquivo']);
//$upload->set_uploads_folder(__DIR__ . '/tmp/');
//$upload->set_file_name('doctrine');
$upload->set_max_size(20);
$upload->set_overwrite(true);
$upload->set_allowed_types(array('image/jpeg', 'text/plain', 'application/pdf'));
try {
$upload->upload_file();
} catch (Exception $ex) {
echo $ex->getMessage();
}
echo $upload->get_file_path();
//var_dump($upload);
示例9: array
/** -------------------------------------
/** Uploading Attachments
/** -------------------------------------*/
function _attach_file()
{
global $IN, $DB, $FNS, $PREFS, $LOC, $LANG, $SESS;
/** -------------------------------------
/** Check the paths
/** -------------------------------------*/
if ($this->upload_path == '') {
return $LANG->line('unable_to_recieve_attach');
}
if (!@is_dir($this->upload_path) or !@is_writable($this->upload_path)) {
return $LANG->line('unable_to_recieve_attach');
}
/** -------------------------------------
/** Are there previous attachments?
/** -------------------------------------*/
$this->attachments = array();
$attachments_size = 0;
if ($IN->GBL('attach') !== FALSE && $IN->GBL('attach') != '') {
$query = $DB->query("SELECT attachment_id, attachment_size, attachment_location\n \t\t\t\t\t\t FROM exp_message_attachments\n \t\t\t\t\t\t WHERE attachment_id IN ('" . str_replace('|', "','", $IN->GBL('attach')) . "')");
if ($query->num_rows + 1 > $this->max_attachments) {
return $LANG->line('no_more_attachments');
} elseif ($query->num_rows > 0) {
foreach ($query->result as $row) {
if (!file_exists($row['attachment_location'])) {
continue;
}
$this->attachments[] = $row['attachment_id'];
$attachments_size += $row['attachment_size'];
}
}
}
/** -------------------------------------
/** Attachment too hefty?
/** -------------------------------------*/
if ($this->attach_maxsize != 0 && $attachments_size + $_FILES['userfile']['size'] / 1024 > $this->attach_maxsize) {
return $LANG->line('attach_too_large');
}
/** -------------------------------------
/** Fetch the size of all attachments
/** -------------------------------------*/
if ($this->attach_total != '0') {
$query = $DB->query("SELECT SUM(attachment_size) AS total FROM exp_message_attachments WHERE is_temp != 'y'");
if (!empty($query->row['total'])) {
// Is the size of the new file (along with the previous ones) too large?
if (ceil($query->row['total'] + $_FILES['userfile']['size'] / 1024) > $this->attach_total * 1000) {
return $LANG->line('too_many_attachments');
}
}
}
/** -------------------------------------
/** Separate the filename form the extension
/** -------------------------------------*/
if (!class_exists('Image_lib')) {
require PATH_CORE . 'core.image_lib' . EXT;
}
$IM = new Image_lib();
$split = $IM->explode_name($_FILES['userfile']['name']);
$filename = $split['name'];
$extension = $split['ext'];
$filehash = $FNS->random('alpha', 20);
/** -------------------------------------
/** Upload the image
/** -------------------------------------*/
if (!class_exists('Upload')) {
require PATH_CORE . 'core.upload' . EXT;
}
$UP = new Upload();
$UP->set_upload_path($this->upload_path);
$UP->set_allowed_types('all');
$UP->new_name = $filehash . $extension;
if (!$UP->upload_file()) {
@unlink($UP->new_name);
if ($UP->error_msg == 'invalid_filetype') {
$info = implode(', ', $UP->allowed_mimes);
$info = "<div class='default'>" . $LANG->line($UP->error_msg) . "<div class='default'>" . $LANG->line('allowed_mimes') . ' ' . $info . "</div>";
return $info;
}
return $UP->error_msg;
}
/** -------------------------------------
/** Insert into Database
/** -------------------------------------*/
$this->temp_message_id = $FNS->random('nozero', 10);
$data = array('attachment_id' => '', 'sender_id' => $this->member_id, 'message_id' => $this->temp_message_id, 'attachment_name' => $filename . $extension, 'attachment_hash' => $filehash, 'attachment_extension' => $extension, 'attachment_location' => $UP->new_name, 'attachment_date' => $LOC->now, 'attachment_size' => ceil($UP->file_size / 1024));
$DB->query($DB->insert_string('exp_message_attachments', $data));
$attach_id = $DB->insert_id;
/** -------------------------------------
/** Change file name with attach ID
/** -------------------------------------*/
// For convenience we use the attachment ID number as the prefix for all files.
// That way they will be easier to manager.
// OK, whatever you say, Rick. -Paul
if (file_exists($UP->new_name)) {
$final_name = $attach_id . '_' . $filehash;
$final_path = $UP->upload_path . $final_name . $extension;
if (rename($UP->new_name, $final_path)) {
chmod($final_path, 0777);
//.........这里部分代码省略.........