Php NicEdit:图片上传到自己的服务器';t工作->;配置错误?

Php NicEdit:图片上传到自己的服务器';t工作->;配置错误?,php,image,upload,nicedit,Php,Image,Upload,Nicedit,更准确地说,我对文本区域的nicEditor有一个问题;图片上传按钮 My file index.php包含调用nicEditor的位置。在同一个文件夹中还有另外两个文件夹:“images”,我想在其中存储文件,“includes”,其中包含nicEdit.js和nicUpload.php(包含官方网站提供的上传代码) 我的问题是:当我想通过nicEdit上传图片时,会出现错误消息“上传图片失败”。尽管我已经设置了以下参数: 在nicEdit.js中,nicURI设置为“includes/ni

更准确地说,我对文本区域的nicEditor有一个问题;图片上传按钮

My file index.php包含调用nicEditor的位置。在同一个文件夹中还有另外两个文件夹:“images”,我想在其中存储文件,“includes”,其中包含nicEdit.js和nicUpload.php(包含官方网站提供的上传代码)

我的问题是:当我想通过nicEdit上传图片时,会出现错误消息“上传图片失败”。尽管我已经设置了以下参数:

  • 在nicEdit.js中,nicURI设置为“includes/nicUpload.php”
  • 在nicUpload.php中,nicUpload_路径被定义为“/images”,nicUpload_URI被定义为“images”(我在这里尝试了几种其他组合,但似乎都不起作用)
  • 文件夹“images”具有777权限
我浪费了几个小时只做尝试和错误,但我无法得到任何积极的结果这样做

[编辑]:

<?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);
}
?>
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 :)
当我上传一个更大的文件时,我可以看到上传栏在前进,但一旦完成,就会出现“上传图像失败”的画面

nicEdit.js中的代码包括:

var nicUploadButton=nicEditorAdvancedButton.extend({nicURI:'includes/nicUpload.php',errorText:"Failed to upload image",addPane:function ......

nicEdit开发人员做了一些不好的事情

他们为
imgur.com
更新了
nicUpload.js
版本,该版本与
nicUpload.php
不兼容。当您从他们的页面下载lib时,服务器只需将
imgur
版本包含到
nicEdit.js

我想知道如何让它工作

在版本23上签出他们的svn存储库

  svn checkout http://svn.nicedit.com//trunk/nicUpload/
  svn update -r 23
编辑未压缩版本的
nicEdit.js
删除代码

/* START CONFIG */
var nicUploadOptions = {
    buttons : {
        'upload' : {name : 'Upload Image', type : 'nicUploadButton'}
    }

粘贴您从svn获得的
nicUpload/
中的
nicUpload.js

并删除该行:

/* NICEDIT_REMOVE_START */,iconFiles : {'upload' : 'src/nicUpload/icons/upload.gif'}/* NICEDIT_REMOVE_END */
解决方案简单

1-创建文件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);
}
?>
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 :)

字体:

简单的解决方案仍然适用于修订版25(压缩)。res数组将被替换,如上所述。确保语法正确
文件大小也有一些限制——实际上是2M。尝试在代码或文件中更改它。不要忘记先创建上传文件夹并添加正确的链接。

希望这对别人有帮助。保持冷静。

如果您是从htaccess保护区上载,您必须删除

C.setRequestHeader("Authorization","Client-ID c37fc05199a05b7");

…在var
nicUploadButton
中,以避免出现提示,而不使用您的登录值。现在似乎可以工作了。

没有一个答案适合我,所以我制作了一个PHP上传程序文件,它检索的对象几乎与imgur相同

这是文件:

uploader.php


在同一台服务器上上载到映像时,我也遇到了此错误[object ProgressEvent],因为从源站“”访问“”处的XMLHttpRequest已被CORS策略阻止:对飞行前请求的响应未通过访问控制检查:飞行前请求不允许重定向。


解决方案:将nicURI:“更改为nicURI:“上载编辑器图像”

您确定包含/nicUpload.php吗?你能粘贴niceEdit.js代码吗?你可以在这里的答案中看到一个工作示例:非常感谢你分享这个!这节省了大量的时间。我按照教程中的说明操作,但现在图像已上载到服务器,但加载栏继续运行,没有停止,因此没有将图像链接返回到编辑器中。知道会出什么问题吗?替换这个数组@dan
$res=array(“data”=>数组(“link”=>$link,“width”=>$data[0],“height”=>$data[1])
define('KB', 1024);
define('MB', 1048576);
define('GB', 1073741824);
define('TB', 1099511627776);
define('semana',  array('','Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado','Domingo'));

function checkImageAttrs($image, $targeFile)
{
    if(getimagesize($image["tmp_name"]) === false)
    {      
        return "El archivo de el archivo no es una imagen.";
    }

    if ($image["size"] > 10*MB) 
    {
       return "Ups, el archivo es muy grande.";        
    }

    $imageFileType = pathinfo($image["name"],PATHINFO_EXTENSION);

    if($imageFileType!="jpg" && $imageFileType!="png" && $imageFileType!="jpeg"  && $imageFileType!="gif" )
    {
        return "Ups, sólo están permitidos los archivos de tipo JPG, JPEG, PNG y GIF.";
    }

   return "OK";
}

function randomPassword($characters_count) {
    $alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
    $pass = array(); //remember to declare $pass as an array
    $alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
    for ($i = 0; $i < $characters_count; $i++) {
        $n = rand(0, $alphaLength);
        $pass[] = $alphabet[$n];
    }
    return implode($pass); //turn the array into a string
}