如何在 froala 所见即所得中更改上传路径
how to change upload path in froala wysiwyg
我正在处理使用 Froala 2.4.0 所见即所得编辑器的项目。
我正在使用 xampp 和本地主机测试。
我无法使用本地路径上传图片和文件,所有文件和图片都上传到:https://i.froala.com/
但我想将所有文件和图像上传到 http://localhost/uploads
怎么办?
我在froala网站上试过了,但是我做不到。
上传图片:
在本地主机中创建“上传”目录,
在上传中创建“图片”目录,
在本地主机中创建一个 php 文件“upload_image.php”,内容如下:
<?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));
}
?>
并将此脚本插件添加到您的编辑器页面:
<script type="text/javascript" src="froala_editor_directory/js/plugins/image.min.js">
并编辑“image.min.js”,将 imageUploadURL 参数更改为:
imageUploadURL:"http://localhost/upload_image.php",
并重复文件上传的所有步骤:
在上传中创建“文件”目录,
在本地主机中创建一个 php 文件“upload_file.php”,内容如下:
<?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));
}
?>
并将此脚本插件添加到您的编辑器页面:
<script type="text/javascript" src="froala_editor_directory/js/plugins/file.min.js">
并编辑“file.min.js”,将 fileUploadURL 参数更改为:
fileUploadURL :"http://localhost/upload_file.php",
最后,如果您收到错误消息“出现问题,请重试”,您应该启用扩展= php_fileinfo.dll,
祝你好运:)
我正在处理使用 Froala 2.4.0 所见即所得编辑器的项目。 我正在使用 xampp 和本地主机测试。 我无法使用本地路径上传图片和文件,所有文件和图片都上传到:https://i.froala.com/ 但我想将所有文件和图像上传到 http://localhost/uploads
怎么办? 我在froala网站上试过了,但是我做不到。
上传图片:
在本地主机中创建“上传”目录,
在上传中创建“图片”目录,
在本地主机中创建一个 php 文件“upload_image.php”,内容如下:
<?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)); } ?>
并将此脚本插件添加到您的编辑器页面:
<script type="text/javascript" src="froala_editor_directory/js/plugins/image.min.js">
并编辑“image.min.js”,将 imageUploadURL 参数更改为:
imageUploadURL:"http://localhost/upload_image.php",
并重复文件上传的所有步骤:
在上传中创建“文件”目录,
在本地主机中创建一个 php 文件“upload_file.php”,内容如下:
<?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)); } ?>
并将此脚本插件添加到您的编辑器页面:
<script type="text/javascript" src="froala_editor_directory/js/plugins/file.min.js">
并编辑“file.min.js”,将 fileUploadURL 参数更改为:
fileUploadURL :"http://localhost/upload_file.php",
最后,如果您收到错误消息“出现问题,请重试”,您应该启用扩展= php_fileinfo.dll,
祝你好运:)