如何更改froala wysiwyg的上传路径 [英] how to change upload path in froala wysiwyg
问题描述
我正在使用xampp和localhost测试。
我无法使用本地路径上传图片和文件,所有文件和图片上传在: https:/ /i.froala.com/
但是我想上传所有文件和图片到 http:// localhost /上传
怎么办?
我在froala网站上试过了,但是我做不到。
上传图片:
- create在本地主机上传uploads目录,
- 在上传文件中创建images目录,
- 在本地主机上创建一个php文件upload_image.php,内容如下:
<?php
//允许扩展。
$ allowedExts = array(gif,jpeg,jpg,png,blob);
//获取文件名。
$ temp = explode(。,$ _FILES [file] [name]);
//获取扩展名。
$ extension = end($ temp);
//在编辑器中进行图像检查,但最好是
//在服务器端再次检查。
//不要使用$ _FILES [file] [type],因为它很容易伪造。
$ finfo = finfo_open(FILEINFO_MIME_TYPE);
$ mime = finfo_file($ finfo,$ _FILES [file] [tmp_name]);
if((($ mime ==image / gif)
||($ mime ==image / jpeg)
||($ mime == image / pjpeg)
||($ mime ==image / x-png)
||($ mime ==image / png))
&& amp ; in_array(strtolower($ extension),$ allowedExts)){
//生成新的随机名称。
$ name = sha1(microtime())。 。 $扩展;
//将文件保存在上传文件夹中。
move_uploaded_file($ _ FILES [file] [tmp_name],getcwd()。/ uploads / images /。
//产生响应。
$ response = new StdClass;
$ response-> link =http:// localhost / uploads / images /。 $名称;
echo stripslashes(json_encode($ response));
}
?>
并将此脚本插件添加到您的编辑器页面:
< script type =text / javascriptsrc =froala_editor_directory / js / plugins / image.min.js>
并编辑image.min.js将imageUploadURL参数更改为:
imageUploadURL:http://localhost/upload_image.php,
并重复所有文件上传步骤:
- 在上传文件中创建files目录,
- 在本地创建一个php文件upload_file.php :
<?php
//获取文件名。
$ temp = explode(。,$ _FILES [file] [name]);
//获取扩展名。
$ extension = end($ temp);
//在编辑器中进行图像检查,但最好是
//在服务器端再次检查。
//不要使用$ _FILES [file] [type],因为它很容易伪造。
$ finfo = finfo_open(FILEINFO_MIME_TYPE);
$ mime = finfo_file($ finfo,$ _FILES [file] [tmp_name]);
$ b $'b'pdf',
'doc',
'docx',
'xls',
' xlsx'
);
$ allowedMimeTypes = array(
'application / x-pdf',
'application / pdf',
'application / msword',
' application / vnd.openxmlformats-officedocument.wordprocessingml.document',
'application / vnd.ms-excel',
'application / vnd.openxmlformats-officedocument.spreadsheetml.sheet'
);
$ b $ if(in_array(strtolower($ extension),$ allowedExts)AND in_array($ mime,$ allowedMimeTypes)){
//生成新的随机名。
$ name = sha1(microtime())。 。 $扩展;
//将文件保存在上传文件夹中。
move_uploaded_file($ _ FILES [file] [tmp_name],getcwd()。/ uploads / files /。$ name);
//产生响应。
$ response = new StdClass;
$ response-> link =http:// localhost / uploads / files /。 $名称;
echo stripslashes(json_encode($ response));
}
?>
并将此脚本插件添加到您的编辑器页面:
< script type =text / javascriptsrc =froala_editor_directory / js / plugins / file.min.js>
并编辑file.min.js将fileUploadURL参数更改为:
fileUploadURL:http://localhost/upload_file.php,
祝你好运:)
I'm working on project which used Froala 2.4.0 WYSIWYG editor. I'm using xampp and localhost test. I can't use local path for upload images and files, all file and image upload in: https://i.froala.com/ But I want upload all file and image to http://localhost/uploads
How to do? I tried in froala website but I cannot do it.
for upload image : - create "uploads" directory in localhost, - create "images" directory in uploads, - create a php file "upload_image.php" in localhost with this content:
<?php
// Allowed extentions.
$allowedExts = array("gif", "jpeg", "jpg", "png", "blob");
// Get filename.
$temp = explode(".", $_FILES["file"]["name"]);
// Get extension.
$extension = end($temp);
// An image check is being done in the editor but it is best to
// check that again on the server side.
// Do not use $_FILES["file"]["type"] as it can be easily forged.
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo, $_FILES["file"]["tmp_name"]);
if ((($mime == "image/gif")
|| ($mime == "image/jpeg")
|| ($mime == "image/pjpeg")
|| ($mime == "image/x-png")
|| ($mime == "image/png"))
&& in_array(strtolower($extension), $allowedExts)) {
// Generate new random name.
$name = sha1(microtime()) . "." . $extension;
// Save file in the uploads folder.
move_uploaded_file($_FILES["file"]["tmp_name"], getcwd() . "/uploads/images/" . $name);
// Generate response.
$response = new StdClass;
$response->link = "http://localhost/uploads/images/" . $name;
echo stripslashes(json_encode($response));
}
?>
and add this script plugin to your editor page :
<script type="text/javascript" src="froala_editor_directory/js/plugins/image.min.js">
and edit "image.min.js" change imageUploadURL parameter to:
imageUploadURL:"http://localhost/upload_image.php",
and repeat all step for file upload : - create "files" directory in uploads, - create a php file "upload_file.php" in localhost with this content:
<?php
// Get filename.
$temp = explode(".", $_FILES["file"]["name"]);
// Get extension.
$extension = end($temp);
// An image check is being done in the editor but it is best to
// check that again on the server side.
// Do not use $_FILES["file"]["type"] as it can be easily forged.
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo, $_FILES["file"]["tmp_name"]);
$allowedExts = array(
'pdf',
'doc',
'docx',
'xls',
'xlsx'
);
$allowedMimeTypes = array(
'application/x-pdf',
'application/pdf',
'application/msword',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/vnd.ms-excel',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
);
if (in_array(strtolower($extension), $allowedExts) AND in_array($mime, $allowedMimeTypes)) {
// Generate new random name.
$name = sha1(microtime()) . "." . $extension;
// Save file in the uploads folder.
move_uploaded_file($_FILES["file"]["tmp_name"], getcwd() . "/uploads/files/" . $name);
// Generate response.
$response = new StdClass;
$response->link = "http://localhost/uploads/files/" . $name;
echo stripslashes(json_encode($response));
}
?>
and add this script plugin to your editor page :
<script type="text/javascript" src="froala_editor_directory/js/plugins/file.min.js">
and edit "file.min.js" change fileUploadURL parameter to:
fileUploadURL :"http://localhost/upload_file.php",
Good luck :)
这篇关于如何更改froala wysiwyg的上传路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!