dab*_*dab 4 php upload image nicedit
关于textareas的nicEditor,我有一个问题,更准确; 图片上传按钮.
我的文件index.php包含调用nicEditor的位置.在同一个文件夹中还有另外两个文件夹:"images",我想要存储文件和"includes",其中nicEdit.js和nicUpload.php(包含官方网站提供的上传代码)是.
我的问题是:当我想通过nicEdit上传图片时,出现错误消息"无法上传图片".看来,虽然我已经设置了以下参数:
我浪费时间只是尝试和错误,但我无法得到任何积极的结果这样做...
[编辑]:
当我上传更大的文件时,我可以看到上传栏正在进行,但是一旦完成,就会出现"无法上传图片"
nicEdit.js中的代码包括:
var nicUploadButton=nicEditorAdvancedButton.extend({nicURI:'includes/nicUpload.php',errorText:"Failed to upload image",addPane:function ......
Run Code Online (Sandbox Code Playgroud)
小智 6
解决方案简单
1 - CREATE FILE image.php和粘贴代码:
<?php
//Check if we are getting the image
if(isset($_FILES['image'])){
//Get the image array of details
$img = $_FILES['image'];
//The new path of the uploaded image, rand is just used for the sake of it
$path = "upload/" . rand().$img["name"];
//Move the file to our new path
move_uploaded_file($img['tmp_name'],$path);
//Get image info, reuiqred to biuld the JSON object
$data = getimagesize($path);
//The direct link to the uploaded image, this might varyu depending on your script location
$link = "http://$_SERVER[HTTP_HOST]"."/nicedit/".$path;
//Here we are constructing the JSON Object
$res = array("upload" => array(
"links" => array("original" => $link),
"image" => array("width" => $data[0],
"height" => $data[1]
)
));
//echo out the response :)
echo json_encode($res);
}
?>
Run Code Online (Sandbox Code Playgroud)
2 - 打开并编辑nickedit.js:
Find the line starting like nicURI:"http://api.imgur.com/2/upload.json"
Replace it with
nicURI:"image.php"
DONE ! Now try uploading something and it would go directly to your server :)
Run Code Online (Sandbox Code Playgroud)
字体: http://manzzup.blogspot.com.br/2014/03/customize-nicedit-image-upload-to.html
| 归档时间: |
|
| 查看次数: |
11237 次 |
| 最近记录: |