本文整理汇总了PHP中upload::file方法的典型用法代码示例。如果您正苦于以下问题:PHP upload::file方法的具体用法?PHP upload::file怎么用?PHP upload::file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类upload
的用法示例。
在下文中一共展示了upload::file方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: files
/**
* Function to upload multi file
*
* @param string $field Field name to upload
* @param string $uploadPath Path to upload
* @param boolean $thumb Auto generate thumbnail or not
* @param string $thumbName If auto generate, this will be used for thumbnail
*/
function files($field, $uploadPath, $newName = null, $thumb = false, $uploadPathThumbs = null, $thumbName = null)
{
$files = JRequest::get('files');
$arrFiles = array();
//rebuild array to re-use function upload::file
foreach ($files['jform']['error'][$field] as $key => $error) {
if (!$error) {
$arrFiles[$key]['jform']['name'][$field] = $files['jform']['name'][$field][$key];
$arrFiles[$key]['jform']['type'][$field] = $files['jform']['type'][$field][$key];
$arrFiles[$key]['jform']['tmp_name'][$field] = $files['jform']['tmp_name'][$field][$key];
$arrFiles[$key]['jform']['error'][$field] = $files['jform']['error'][$field][$key];
$arrFiles[$key]['jform']['size'][$field] = $files['jform']['size'][$field][$key];
}
}
$result = array();
$i = 1;
foreach ($arrFiles as $key => $file) {
if ($newName) {
$newName = $i . '-' . $newName;
}
$i++;
$result[$key] = upload::file($file['jform'], $field, $uploadPath, $newName, $thumb, $uploadPathThumbs, $thumbName);
}
return $result;
}
示例2: editFont
public function editFont($id = '')
{
$file = dirname(ROOT) . DS . 'data' . DS . 'fonts.json';
include_once ROOT . DS . 'includes' . DS . 'functions.php';
include_once ROOT . DS . 'includes' . DS . 'upload.php';
$dg = new dg();
$fonts = $dg->readFile($file);
$fonts = json_decode($fonts, true);
$font = $fonts['fonts']['fonts'];
$data = array();
$data['error'] = '';
$data['id'] = $id;
// get categories.
$cate_font = ROOT . DS . 'data' . DS . 'font_categories.json';
$cate = $dg->readFile($cate_font);
$cates = json_decode($cate, true);
$data['categories'] = $cates;
// post data.
if (isset($_POST['title']) && $_POST['title'] != '') {
$title = $_POST['title'];
//upload.
$path = dirname(ROOT) . DS . 'data' . DS . 'fonts';
if (!file_exists($path)) {
mkdir($path, 0755);
}
$up = new upload();
$up->permission = 755;
$up->path = $path;
$up->file_size = 2097152;
// 2mb.
$count = 0;
$result = array();
if (count($_FILES) == 3) {
foreach ($_FILES as $key => $value) {
if (isset($_FILES[$key]['name']) && $_FILES[$key]['name'] != '') {
$checkname = array('~', '`', '!', '@', '#', '$', '%', '^', '&', '(', ')', '+', '=', '[', ']', '{', '}', ':', ' ', ',', '\'', ';');
$up->file_name = str_replace($checkname, '', $_FILES[$key]['name']);
if ($count == 0) {
$up->file_type[0] = 'woff';
$val = $up->file($_FILES[$key]);
if ($val['error'] == 1) {
$data['error'] = $val['msg'];
break;
}
$result[$count] = $val;
} elseif ($count == 1) {
$up->file_type[0] = 'ttf';
$up->file_type[1] = 'TTF';
$val = $up->file($_FILES[$key]);
if ($val['error'] == 1) {
$data['error'] = $val['msg'];
if (file_exists($result[0]['full_path'])) {
unlink($result[0]['full_path']);
}
break;
}
$result[$count] = $val;
} else {
$up->file_type[0] = 'jpg';
$up->file_type[1] = 'png';
$up->file_type[2] = 'gif';
$up->file_type[3] = 'jpeg';
$val = $up->file($_FILES[$key]);
if ($val['error'] == 1) {
$data['error'] = $val['msg'];
if (file_exists($result[0]['full_path'])) {
unlink($result[0]['full_path']);
}
if (file_exists($result[1]['full_path'])) {
unlink($result[1]['full_path']);
}
break;
}
$result[$count] = $val;
}
}
$count++;
}
}
//process.
$subtitle = '';
$cate_id = '';
$catename = '';
if (isset($_POST['subtitle'])) {
$subtitle = $_POST['subtitle'];
}
if (isset($_POST['cate_id'])) {
$cate_id = $_POST['cate_id'];
}
if ($catename == '' && isset($cates[$cate_id])) {
$catename = $cates[$cate_id];
}
if ($id != '') {
if (count($font) && $data['error'] == '') {
$font_out = array();
foreach ($font as $key => $val) {
if ($val['id'] == $id && $val['type'] == '') {
$filename = $val['filename'];
$path = $val['path'];
$thumb = $val['thumb'];
//.........这里部分代码省略.........
示例3: replaceFile
static function replaceFile()
{
global $page;
$filename = get('filename');
$file = $page->files()->find($filename);
if (!$file) {
return array('status' => 'error', 'msg' => l::get('files.replace.errors.notfound'));
}
$upload = upload::file('file', $page->root() . '/' . $filename);
if (error($upload)) {
return $upload;
}
self::killCache();
return array('status' => 'success', 'msg' => l::get('files.replace.success'));
}
示例4: uploadFiles
function uploadFiles($fileName, $uploadPath)
{
//require upload file
require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'helpers/upload.class.php';
//define upload path
$uploadPathMore = date('Y') . DS . date('m') . DS . date('d') . DS;
$uploadPath .= $uploadPathMore;
//echo $uploadPath; die;
$files = JRequest::get('files');
$post = JRequest::get('post');
$files = $files['jform'];
$name = array();
$data = array();
foreach ($post['jform']['images']['type'] as $key => $type) {
if ($files['name']['images'][$key] != '' && !$files['error']['images'][$key]) {
//set image name
$imageName = $fileName . '-' . time() . '.' . end(explode('.', $files['name']['images'][$key]));
//upload file
$upload = upload::file($files, 'images', $uploadPath, $imageName, $key, false);
//if upload OK
if (is_array($upload) && $upload['result'] == 'OK') {
$data[] = array('image' => str_replace(DS, '/', $uploadPathMore) . $upload['file_name'], 'type' => $type);
} else {
JError::raiseNotice('UPLOAD_ERROR', 'Upload Error');
}
}
}
//$data = serialize($data);
return $data;
}