【发布时间】:2015-03-30 00:12:27
【问题描述】:
我已经阅读Froala Help Docs 超过 10 次了。我仍然无法让它工作:(
当我在编辑器中单击上传图标并选择要上传的图像时,没有任何反应。弹出要求您选择图像的对话框,选择图像后,它会关闭,但之后页面上没有任何反应。
我的代码肯定有问题。但是,我不知道它是什么。
我的查看页面:
<textarea id="edit" name="message"> </textarea>
我的js:
$(function() {
$('#edit').editable({
height: 400,
imageUploadURL: '/assets/upload_image.php',
imageUploadParams: {id: "edit"},
imageUploadParams: {id: "edit"},
placeholder: "Write something...",
inlineMode: false
})
});
我的upload_image.php 文件:
<?php
// Allowed extentions.
$allowedExts = array("gif", "jpeg", "jpg", "png");
// 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($extension, $allowedExts)) {
// Generate new random name.
$name = sha1(microtime()) . "." . $extension;
// Save file in the uploads folder.
move_uploaded_file($_FILES["file"]["tmp_name"], getcwd() . "http://localhost/assets/uploads/" . $name);
// Generate response.
$response = new StdClass;
$response->link = "http://localhost/assets/uploads/" . $name;
echo stripslashes(json_encode($response));
}
我尝试解决此问题的方法:
在upload_image.php 中,我已将上传文件夹路径(原始:http://localhost/assets/uploads/ 替换为 uploads 并在该目录中创建了一个 uploads 文件夹。仍然没有运气。
我尝试将所有文件放在同一个文件夹中,但没有成功。
非常感谢任何帮助。
【问题讨论】:
-
打开你的开发者工具,进入网络标签。是否发送请求?您在客户端或服务器上收到任何错误吗?
-
你确保 ajax 中的路径 url 正确吗?和upload_image.php 可以处理吗?在您的 upload_image.php 和 die() 中尝试 print_r(something);在顶部确保(调试)。
标签: javascript php jquery file-upload