За последние 24 часа нас посетили 56018 программистов и 1770 роботов. Сейчас ищут 1253 программиста ...

Загрузка картинки через nicEdit на свой хост

Тема в разделе "PHP для новичков", создана пользователем bkm, 14 сен 2012.

  1. bkm

    bkm Активный пользователь

    С нами с:
    22 окт 2009
    Сообщения:
    299
    Симпатии:
    0
    вызываем визуальный редактор nicEdit
    uploadURI = путь к файлу загрузки

    Код (Text):
    1. <script type='text/javascript' language='javascript'>new nicEditor({fullPanel : true, uploadURI: 'http://mysite.ru/nicUpload.php'}).panelInstance('uni_id');</script>
    PHP код файла nicUpload.php
    Код (PHP):
    1. <?php
    2.  
    3. $uploaddir = 'img/';
    4. $file = $uploaddir . basename($_FILES['nicImage']['name']);
    5.  
    6. if (move_uploaded_file($_FILES['nicImage']['tmp_name'], $file)) {
    7. $type_file = get_typefile($_FILES['nicImage']['name'], ".");
    8.  
    9. if ($type_file==".gif" || $type_file==".jpg" || $type_file==".jpeg" || $type_file==".png"){
    10.  
    11.     $tmp_name = date('U');
    12.     $newname = $tmp_name."".$type_file;
    13.     rename ($uploaddir . basename($_FILES['nicImage']['name']), $uploaddir . basename($newname)); 
    14.     
    15.     echo "Успешно!";
    16.  
    17.     } else {
    18.     echo "Разрешены только gif, jpg, jpeg, png файлы!"; 
    19.     unlink ($file);
    20.     }
    21.  
    22.   } else {
    23.     echo "произошла ошибка загрузки, попробуйте ещё раз.". $file;
    24. }
    25.  
    26. function get_typefile($file, $t=""){
    27.     $tmp = explode(".", $file);
    28.     return strtolower($t.$tmp[count($tmp)-1]);
    29. }
    30. ?>
    Файл загружается, но в редактор не вставляется, ума не приложу, что делать.
    NicEdit можно скачать с сайта _http://www.nicedit.com/
     
  2. DiscoInferno

    DiscoInferno Активный пользователь

    С нами с:
    16 авг 2011
    Сообщения:
    20
    Симпатии:
    0
    Адрес:
    Москва
    Я с этим редактором не работал.
    А пробовали на официальном сайте вопрос задать? Есть там служба поддержки?
     
  3. bkm

    bkm Активный пользователь

    С нами с:
    22 окт 2009
    Сообщения:
    299
    Симпатии:
    0
    Уже несколько лет сайт не меняется и форум неактивен. Редактор устраивает со всех сторон, самое главное очень легкий и функциональный.

    Вот эта строчка выполняет загрузку файла

    Код (PHP):
    1. var nicUploadButton=nicEditorAdvancedButton.extend({nicURI:"http://files.nicedit.com/",addPane:function(){this.im=this.ne.selectedInstance.selElm().parentTag("IMG");this.myID=Math.round(Math.random()*Math.pow(10,15));this.requestInterval=1000;this.uri=this.ne.options.uploadURI||this.nicURI;nicUploadButton.lastPlugin=this;this.myFrame=new bkElement("iframe").setAttributes({width:"100%",height:"100px",frameBorder:0,scrolling:"no"}).setStyle({border:0}).appendTo(this.pane.pane);this.progressWrapper=new bkElement("div").setStyle({display:"none",width:"100%",height:"20px",border:"1px solid #ccc"}).appendTo(this.pane.pane);this.progress=new bkElement("div").setStyle({width:"0%",height:"20px",backgroundColor:"#ccc"}).setContent("&nbsp").appendTo(this.progressWrapper);setTimeout(this.addForm.closure(this),50)},addForm:function(){var A=this.myDoc=this.myFrame.contentWindow.document;A.open();A.write("<html><body>");A.write('<form method="post" action="'+this.uri+"?id="+this.myID+'" enctype="multipart/form-data">');A.write('<input type="hidden" name="APC_UPLOAD_PROGRESS" value="'+this.myID+'" />');A.write('<div style="font-size: 14px; font-weight: bold; padding-top: 5px;">Загрузка изображения</div>');A.write('<input name="nicImage" type="file" style="margin-top: 10px;" />');A.write("</form>");A.write("</body></html>");A.close();this.myBody=A.body;this.myForm=$BK(this.myBody.getElementsByTagName("form")[0]);this.myInput=$BK(this.myBody.getElementsByTagName("input")[1]).addEvent("change",this.startUpload.closure(this));this.myStatus=new bkElement("div",this.myDoc).setStyle({textAlign:"center",fontSize:"14px"}).appendTo(this.myBody)},startUpload:function(){this.myForm.setStyle({display:"none"});this.myStatus.setContent('<strong>Загрузка...</strong><br />Пожалуйста, подождите');this.myForm.submit();setTimeout(this.makeRequest.closure(this),this.requestInterval)},makeRequest:function(){if(this.pane&&this.pane.pane){nicUploadButton.lastPlugin=this;var A=new bkElement("script").setAttributes({type:"text/javascript",src:this.uri+"?check="+this.myID+"&rand="+Math.round(Math.random()*Math.pow(10,15))}).addEvent("load",function(){A.parentNode.removeChild(A)}).appendTo(document.getElementsByTagName("head")[0]);if(this.requestInterval){setTimeout(this.makeRequest.closure(this),this.requestInterval)}}},setProgress:function(A){this.progressWrapper.setStyle({display:"block"});this.progress.setStyle({width:A+"%"})},update:function(C){if(C==false){this.progressWrapper.setStyle({display:"none"})}else{if(C.url){this.setProgress(100);this.requestInterval=false;if(!this.im){this.ne.selectedInstance.restoreRng();var B="javascript:nicImTemp();";this.ne.nicCommand("insertImage",B);this.im=this.findElm("IMG","src",B)}var A=parseInt(this.ne.selectedInstance.elm.getStyle("width"));if(this.im){this.im.setAttributes({src:C.url,width:(A&&C.width)?Math.min(A,C.width):""})}this.removePane()}else{if(C.error){this.requestInterval=false;this.setProgress(100);alert("Произошла ошибка при загрузке ("+C.error+").");this.removePane()}else{if(C.noprogress){this.progressWrapper.setStyle({display:"none"});if(this.uri.indexOf("http:")==-1||this.uri.indexOf(window.location.host)!=-1){this.requestInterval=false}}else{this.setProgress(Math.round((C.current/C.total)*75));if(C.interval){this.requestInterval=C.interval}}}}}}});nicUploadButton.statusCb=function(A){nicUploadButton.lastPlugin.update(A)};nicEditors.registerPlugin(nicPlugin,nicUploadOptions); 
     
  4. Lead Pepelats

    Lead Pepelats Новичок

    С нами с:
    5 дек 2013
    Сообщения:
    1
    Симпатии:
    0
    Для решения проблемы загрузки изображений на свой хост через NicEdit я дописал дополнительный инструмент для NicEdit-а, ознакомиться с которым (и скачать) можно здесь -> http://lead-pepelats.ru/blog/images-manager-for-nicedit/