문제

IM은 NICUPLOAD 플러그인으로 NICINEIT를 구현하려고하지만 업로드 할 파일을 선택하면 "이미지를 업로드하지 못했습니다"라고 서버 응답은 "잘못된 업로드 ID"라고합니다.

스크립트를 호출하고 초기화하는 코드입니다.

<script src="http://js.nicedit.com/nicEdit-latest.js" type="text/javascript"></script>
<script type="text/javascript">//<![CDATA[
bkLib.onDomLoaded(function() {
new nicEditor({uploadURI : '../../nicedit/nicUpload.php'}).panelInstance('area1');
});
//]]>
</script>
.

nicupload.php의 경로가 올바르고 있으며 코드는 http://niceit.com/src/nicupload/nicupload.js

업로드 폴더가 변경되었으며 쓰기 권한을 설정했습니다.문서에 따르면 ( http://wiki.nicedit.com/w/page/515 / Configuration % 20Options ), 그게 전부하지만 오류가 계속 발생합니다.어떤 아이디어도 있습니까?

도움이 되었습니까?

해결책

수동으로 ID를 스크립트에 전달할 수 있습니다. e.g nicupload.php? id= intropicheader 및 정의한 이미지 폴더에 intropicheader.jpg (또는 적절한 확장자)가됩니다.

그러나이 스크립트가 끊어지고 NiceditoRadvantedButton.Extend 동안 NicedIt.js에서 직접 지정된 경우 구성 옵션 Uploaduri에 액세스 할 수 없음을 알아 차렸다 ({. 이로 인한 "알 수없는"자원에 액세스하면 .

문서는 별도로 암시하고 Nicuri가 imgur.com에 대해 여기에 지정되었다는 사실을 의미합니다 (어쩌면 기본값으로) 나는 나에게 uploaduri를 uploaduri 참조를 nicupload.php 스크립트에 추가 할 수 있고 단일 장소에서 모든 편집자 인스턴스화.

업데이트

인스턴스화 중에 전달하면 작동합니다.이 추측은 쉽게 동적 ID 인구를 허용합니다.

불행히도, nicupload.php는 오류가 있고 출력이 JSON이 아닙니다. 편집기는 JSON을 구문 분석하고 예기치 않은 토큰 "<"로 스크립트 태그 및 오류를 찾을 것으로 예금합니다.

식별을 시도하는 다른 오류의 뗏목이 있습니다.

nicedit.js

  1. a.append ( "Image")는 내효가되어야합니다 ( "Nicimage")
  2. this.onploaded (d.upload)는이 (d.upload)가되어야합니다. (d)
  3. this.onuploaded (d)는 VAR D= JSON.PARSE (C.RESPONSETEXT) 이후의 시도 차단 내에서 이동하여 가변 범위 문제를 수정하기 위해 를 수정해야합니다.
  4. b.image.width는 b.width 가 될 필요가있다

    nicupload.php

    1. JSON 출력이 올바르게 형성되지 않고 HTML 출력을 주석 처리하고 JSON_ENCODE ($ 상태)로 출력합니다.
    2. JSON 출력은 var d= b.Link의 이름을 nicedit.js에서 var d= b.URL에 이름을 바꾸는 것에 따라 URL이 아닌 링크라는 키 / 값 쌍을 리턴해야합니다.

      PHP와 JavaScript 코드는 모두 원하는 것으로 남기고, 나는 많은 오류를 정기적으로 얻고 자신을 고치고 있습니다.

다른 팁

솔루션을 원한다면 오랜 시간 (실제 솔루션이없는 많은 게시물) 이제 코드를 자신을 고쳤습니다.이제 이미지를 내 자신의 서버에 업로드 할 수 있습니다.Thx firebug 및 Eclipse; -)

주요 문제는 nicupload.php가 오래되었고 현재 nicedit-upload 기능으로 작동하지 않는다는 것입니다.

누락은 오류 처리가 필요합니다.이를 자유롭게 추가하십시오 ...

niceditor를 PHP 파일에 추가하고 을 구성하여 nicedit.php : 를 사용하십시오.

new nicEditor({iconsPath : 'pics/nicEditorIcons.gif', uploadURI : 'script/nicUpload.php'}
.

niceit.js 비 압축 를 다운로드하고 nicedit.js에서 다음 행을 변경하십시오.

uploadFile : function() {
var file = this.fileInput.files[0];
if (!file || !file.type.match(/image.*/)) {
  this.onError("Only image files can be uploaded");
  return;
}
this.fileInput.setStyle({ display: 'none' });
this.setProgress(0);

var fd = new FormData(); 
fd.append("image", file);
fd.append("key", "b7ea18a4ecbda8e92203fa4968d10660");
var xhr = new XMLHttpRequest();
xhr.open("POST", this.ne.options.uploadURI || this.nicURI);

xhr.onload = function() {
  try {
    var res = JSON.parse(xhr.responseText);
  } catch(e) {
    return this.onError();
  }
  //this.onUploaded(res.upload); // CHANGE HERE
  this.onUploaded(res);
}.closure(this);
xhr.onerror = this.onError.closure(this);
xhr.upload.onprogress = function(e) {
  this.setProgress(e.loaded / e.total);
}.closure(this);
xhr.send(fd);
.

},

onUploaded : function(options) {
this.removePane();
//var src = options.links.original; // CHANGE HERE
var src = options['url'];
if(!this.im) {
  this.ne.selectedInstance.restoreRng();
  //var tmp = 'javascript:nicImTemp();';
  this.ne.nicCommand("insertImage", src);
  this.im = this.findElm('IMG','src', src);
}
var w = parseInt(this.ne.selectedInstance.elm.getStyle('width'));
if(this.im) {
  this.im.setAttributes({
    src : src,
    width : (w && options.image.width) ? Math.min(w, options.image.width) : ''
  });
}
.

}

와 같은 nicupload.php를 변경하십시오

<?php
/* NicEdit - Micro Inline WYSIWYG
 * Copyright 2007-2009 Brian Kirchoff
 *
 * NicEdit is distributed under the terms of the MIT license
 * For more information visit http://nicedit.com/
 * Do not remove this copyright message
 *
 * nicUpload Reciever Script PHP Edition
 * @description: Save images uploaded for a users computer to a directory, and
 * return the URL of the image to the client for use in nicEdit
 * @author: Brian Kirchoff <briankircho@gmail.com>
 * @sponsored by: DotConcepts (http://www.dotconcepts.net)
 * @version: 0.9.0
 */

/* 
* @author: Christoph Pahre
* @version: 0.1
* @description: different modification, so that this php file is working with the newest nicEdit.js (needs also modification - @see) 
* @see http://stackoverflow.com/questions/11677128/nicupload-says-invalid-upload-id-cant-make-it-works
*/

define('NICUPLOAD_PATH', '../images/uploadedImages'); // Set the path (relative or absolute) to
                                      // the directory to save image files

define('NICUPLOAD_URI', '../images/uploadedImages');   // Set the URL (relative or absolute) to
                                      // the directory defined above

$nicupload_allowed_extensions = array('jpg','jpeg','png','gif','bmp');

if(!function_exists('json_encode')) {
    die('{"error" : "Image upload host does not have the required dependicies (json_encode/decode)"}');
}

if($_SERVER['REQUEST_METHOD']=='POST') { // Upload is complete

    $file = $_FILES['image'];
    $image = $file['tmp_name'];
    $id = $file['name'];

    $max_upload_size = ini_max_upload_size();
    if(!$file) {
        nicupload_error('Must be less than '.bytes_to_readable($max_upload_size));
    }

    $ext = strtolower(substr(strrchr($file['name'], '.'), 1));
    @$size = getimagesize($image);
    if(!$size || !in_array($ext, $nicupload_allowed_extensions)) {
        nicupload_error('Invalid image file, must be a valid image less than '.bytes_to_readable($max_upload_size));
    }

    $filename = $id;
    $path = NICUPLOAD_PATH.'/'.$filename;

    if(!move_uploaded_file($image, $path)) {
        nicupload_error('Server error, failed to move file');
    }

    $status = array();
    $status['done'] = 1;
    $status['width'] = $size[0];
    $rp = realpath($path);
    $status['url'] =  NICUPLOAD_URI ."/".$id;


    nicupload_output($status, false);
    exit;
} 

// UTILITY FUNCTIONS

function nicupload_error($msg) {
    echo nicupload_output(array('error' => $msg)); 
}

function nicupload_output($status, $showLoadingMsg = false) {
    $script = json_encode($status);
    $script = str_replace("\\/", '/', $script);
    echo $script;

    exit;
}

function ini_max_upload_size() {
    $post_size = ini_get('post_max_size');
    $upload_size = ini_get('upload_max_filesize');
    if(!$post_size) $post_size = '8M';
    if(!$upload_size) $upload_size = '2M';

    return min( ini_bytes_from_string($post_size), ini_bytes_from_string($upload_size) );
}

function ini_bytes_from_string($val) {
    $val = trim($val);
    $last = strtolower($val[strlen($val)-1]);
    switch($last) {
        // The 'G' modifier is available since PHP 5.1.0
        case 'g':
            $val *= 1024;
        case 'm':
            $val *= 1024;
        case 'k':
            $val *= 1024;
    }
    return $val;
}

function bytes_to_readable( $bytes ) {
    if ($bytes<=0)
        return '0 Byte';

    $convention=1000; //[1000->10^x|1024->2^x]
    $s=array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB');
    $e=floor(log($bytes,$convention));
    return round($bytes/pow($convention,$e),2).' '.$s[$e];
}

?>
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top