高分求thinkphp中设置xheditor图片上传详细步骤。。。
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了高分求thinkphp中设置xheditor图片上传详细步骤。。。相关的知识,希望对你有一定的参考价值。
本人对JS一窍不通。。。希望能说简单一些。。。
从图像中如何出现“上传”按钮,如何调用upImgUrl,如何配置upload.php开始说起,感谢万分。
网上找了那些都是配置upload.php,并没有说如何调用“上传”按钮upImgUrl,我一点都不懂JS额。。。初学。。。
先在页面上面配置获取百度配置文件地址:window.UEDITOR_CONFIG.serverUrl = xx;
后面的就是服务器端了
use Admin\\Service\\BaseService;
class UeditorController extends BaseService
public function _empty()
$action = I('get.action','','htmlspecialchars');
$callback = I('get.callback');
$result = null;
switch ($action)
case 'config':
$result = json_encode($this->_Config());
break;
/* 上传图片 */
case 'uploadimage':
/* 上传涂鸦 */
case 'uploadscrawl':
/* 上传视频 */
case 'uploadvideo':
/* 上传文件 */
case 'uploadfile':
$result = $this->_Upload($action);
break;
/* 列出图片 */
case 'listimage':
/* 列出文件 */
case 'listfile':
$result = $this->_list($action);
break;
/* 抓取远程文件 */
case 'catchimage':
$result = $this->_crawler();
break;
default:
$result = json_encode(array(
'state'=> '请求地址出错'
));
break;
if (isset($_GET["callback"]))
if (preg_match("/^[\\w_]+$/", $_GET["callback"]))
echo htmlspecialchars($_GET["callback"]) . '(' . $result . ')';
else
echo json_encode(array(
'state'=> 'callback参数不合法'
));
else
echo $result;
private function _Config()
$CONFIG = json_decode(preg_replace("/\\/\\*[\\s\\S]+?\\*\\//", "", file_get_contents(APP_PATH .'Admin/Conf/config.json')), true);
$CONFIG['imageMaxSize'] = UPLOAD_IMAGE_SIZE;
$CONFIG['scrawlMaxSize'] = UPLOAD_IMAGE_SIZE;
$CONFIG['catcherMaxSize'] = UPLOAD_IMAGE_SIZE;
$CONFIG['videoMaxSize'] = UPLOAD_VIDEO_SIZE;
$CONFIG['fileMaxSize'] = UPLOAD_FILE_SIZE;
$CONFIG['scrawlUrlPrefix'] = ATTACH_URL;
$CONFIG['imageUrlPrefix'] = ATTACH_URL;
$CONFIG['snapscreenUrlPrefix'] = ATTACH_URL;
$CONFIG['catcherUrlPrefix'] = ATTACH_URL;
$CONFIG['videoUrlPrefix'] = ATTACH_URL;
$CONFIG['fileUrlPrefix'] = ATTACH_URL;
$CONFIG['imageManagerUrlPrefix'] = ATTACH_URL;
$CONFIG['fileManagerUrlPrefix'] = ATTACH_URL;
return $CONFIG;
private function _Upload($action)
$config = $this->_Config();
$up = new \\Lib\\Extend\\Upload();
$type = '';
switch ($action)
case 'uploadimage':
$fieldName = $config['imageFieldName'];
$type = 'image';
break;
case 'uploadscrawl':
$fieldName = $config['scrawlFieldName'];
$type = 'base64';
break;
case 'uploadvideo':
$fieldName = $config['videoFieldName'];
$type = 'video';
break;
case 'uploadfile':
default:
$fieldName = $config['fileFieldName'];
$type = 'file';
break;
if($type == 'base64')
$result = $up->saveBase64($fieldName);
else
$result = $up->save($fieldName,$type);
return json_encode($result);
private function _list($action)
$config = $this->_Config();
switch ($action)
/* 列出文件 */
case 'listfile':
$allowFiles = $config['fileManagerAllowFiles'];
$listSize = $config['fileManagerListSize'];
break;
/* 列出图片 */
case 'listimage':
default:
$allowFiles = $config['imageManagerAllowFiles'];
$listSize = $config['imageManagerListSize'];
$allowFiles = substr(str_replace(".", "|", join("", $allowFiles)), 1);
/* 获取参数 */
$size = isset($_GET['size']) ? htmlspecialchars($_GET['size']) : $listSize;
$start = isset($_GET['start']) ? htmlspecialchars($_GET['start']) : 0;
$end = $start + $size;
/* 获取文件列表 */
$path = UPLOAD_PATH;
$files = $this->_getfiles($path, $allowFiles);
if (!count($files))
return json_encode(array(
"state" => "no match file",
"list" => array(),
"start" => $start,
"total" => count($files)
));
/* 获取指定范围的列表 */
$len = count($files);
for ($i = min($end, $len) - 1, $list = array(); $i < $len && $i >= 0 && $i >= $start; $i--)
$list[] = $files[$i];
return json_encode(array(
"state" => "SUCCESS",
"list" => $list,
"start" => $start,
"total" => count($files)
));
private function _getfiles($path, $allowFiles, &$files = array())
if (!is_dir($path)) return null;
if(substr($path, strlen($path) - 1) != '/') $path .= '/';
$handle = opendir($path);
while (false !== ($file = readdir($handle)))
if ($file != '.' && $file != '..')
$path2 = $path . $file;
if (is_dir($path2))
$this->_getfiles($path2, $allowFiles, $files);
else
if (preg_match("/\\.(".$allowFiles.")$/i", $file))
$files[] = array(
'url'=> substr($path2, strlen(UPLOAD_PATH)),
'mtime'=> filemtime($path2)
);
return $files;
private function _crawler()
$config = $this->_Config();
$fieldName = $config['catcherFieldName'];
$up = new \\Lib\\Extend\\Upload();
$source = I($fieldName);
$result = array();
foreach($source as $imgUrl)
$item = $up->saveRemote($imgUrl);
array_push($list, array(
"state" => $item["state"],
"url" => $item["url"],
"size" => $item["size"],
"title" => htmlspecialchars($item["title"]),
"original" => htmlspecialchars($item["original"]),
"source" => htmlspecialchars($imgUrl)
));
return json_encode($result);
使用文件选择器在图像 UI 元素中设置图片
【中文标题】使用文件选择器在图像 UI 元素中设置图片【英文标题】:setting picture in image UI element using file picker 【发布时间】:2013-05-21 09:56:30 【问题描述】:在我的应用程序中,用户可以从设备内存(即平板电脑内存或桌面本地驱动器)设置配置文件图片并将其上传到服务器。 我使用了文件选择器,以便用户可以选择一张图片并将其设置为个人资料图片,但问题是图片没有粘在 Image 元素上。 我的代码:
private async void filePicker()
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
openPicker.FileTypeFilter.Add(".jpg");
openPicker.FileTypeFilter.Add(".jpeg");
openPicker.FileTypeFilter.Add(".png");
StorageFile file = await openPicker.PickSingleFileAsync();
if (file != null)
String filePath = file.Path;
System.Diagnostics.Debug.WriteLine(filePath);
Uri uri = new Uri(filePath, UriKind.Relative);
profilePicture.Source = new BitmapImage(uri);
internal bool EnsureUnsnapped()
// FilePicker APIs will not work if the application is in a snapped state.
// If an app wants to show a FilePicker while snapped, it must attempt to unsnap first
bool unsnapped = ((ApplicationView.Value != ApplicationViewState.Snapped) || ApplicationView.TryUnsnap());
if (!unsnapped)
//NotifyUser("Cannot unsnap the sample.", NotifyType.StatusMessage);
return unsnapped;
我得到的文件路径是这个
filePath=C:\Users\Prateek\Pictures\IMG_0137.JPG
我不知道出了什么问题。
【问题讨论】:
【参考方案1】:我不确定这是否能解决问题,这是我设置图像源时所做的。
使用位图图像作为图像源
BitmapImage bitmapimage = new BitmapImage();
StorageFile file = await openPicker.PickSingleFileAsync();
var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
await bitmapimage.SetSourceAsync(stream);
profilePicture.Source = bitmapImage;
【讨论】:
【参考方案2】:我用过这段代码……
var picker = new Windows.Storage.Pickers.FileOpenPicker();
picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
picker.FileTypeFilter.Add(".jpg");
picker.FileTypeFilter.Add(".jpeg");
picker.FileTypeFilter.Add(".png");
Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();
if (file != null)
this.textBlock.Text =
"File Path: " + file.Path + Environment.NewLine +
"File Name: " + file.Name;
try
var stream = await file.OpenReadAsync();
var imageSource = new BitmapImage();
await imageSource.SetSourceAsync(stream);
this.image.Source = imageSource;
catch (Exception ex)
this.textBlock.Text = ex.ToString();
else
this.textBlock.Text = "Operation cancelled.";
【讨论】:
以上是关于高分求thinkphp中设置xheditor图片上传详细步骤。。。的主要内容,如果未能解决你的问题,请参考以下文章