2012-09-04 40 views
3

我正在使用CKEditor和CKFinder。兩者都很好。當我瀏覽(或直接複製)一個圖像(或閃存)到CKEditor時,它會顯示在其中並插入到MySql數據庫中。CKEditor和CkFinder在PHP中工作正常,但不顯示圖像,閃存等

將它插入MySql數據庫之後,我試圖在HTML表格中顯示它,並且不顯示它,並顯示替代文本。

通過CKFinder瀏覽圖像後的圖像路徑如下所示。

<img alt="" src="/ckfinder/userfiles/images/1243_SS_2502.jpg" style="width: 490px; height: 618px;" /> 

插入數據庫的內容如下。

&lt;img alt=&quot;\&amp;quot;\&amp;quot;&quot; data-cke-saved-src=&quot;\&quot; 

src=&quot;\&amp;quot;/ckfinder/userfiles/images/1243_SS_2502.jpg\&amp;quot;&quot; st yle=& 

quot;\&amp;quot;width:&quot; 490px;=&quot;&quot; height:=&quot;&quot; 618px;\&quot;= quot;&quot;&gt; 

嘗試與htmlentities()仍然無法正常工作。在使用JSTL/EL處理JSP時,我必須執行以下操作。

<c:out value="${str}" default="No content found." escapeXml="false"/> 

escapeXml="false",其中str寫入EL是java.lang.String轉換後保持在Oracle clob數據。

解決PHP中的情況的方式是什麼? CKEditor和CKFinder都適合我。


$ckeditor = new CKEditor(); 
$ckeditor->basePath = 'ckeditor/'; 
$ckeditor->config['filebrowserBrowseUrl'] = 'ckfinder/ckfinder.html'; 
$ckeditor->config['filebrowserImageBrowseUrl'] = 'ckfinder/ckfinder.html?type=Images'; 
$ckeditor->config['filebrowserFlashBrowseUrl'] = 'ckfinder/ckfinder.html?type=Flash'; 
$ckeditor->config['filebrowserUploadUrl'] = 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files'; 
$ckeditor->config['filebrowserImageUploadUrl'] = 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images'; 
$ckeditor->config['filebrowserFlashUploadUrl'] = 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash'; 
$ckeditor->editor('description', $ed_about_us); 

編輯:

<?php include_once("Lock.php");?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Wagafashion</title> 

<link rel="stylesheet" href="css/validationEngine.jquery.css" type="text/css"/> 
<link rel="stylesheet" href="css/template.css" type="text/css"/> 
<!--<script type="text/javascript" language="javascript" src="ckeditor/ckeditor.js"></script>--> 
<script src="js/jquery-1.6.min.js" type="text/javascript"></script>   
<script src="js/languages/jquery.validationEngine-en.js" type="text/javascript" charset="utf-8"></script> 

<script src="js/jquery.validationEngine.js" type="text/javascript" charset="utf-8"></script><script> 
    jQuery(document).ready(function(){ 
     // binds form submission and fields to the validation engine 
     jQuery("#dataForm").validationEngine(); 
    });    
</script> 

<script language="javascript" type="text/javascript"> 
    function deleteSingle(id) 
    {  
     var delId=confirm("About us with the id "+id+" is about to be deleted permanently.\n\nAttention : This action will never be undone!\n\nAre you sure...???");   
     return(delId==true?true:false); 
    } 

</script> 

</head> 

<body> 
<?php 
    include_once("Connection.php"); 
    include_once("ckeditor/ckeditor.php"); 
    $con=new Connection(); 
    $con->get_connection(); 

    $ed_about_us=""; 
    $flag=-1; 
    $msg=""; 

    if(isset($_POST['btnSubmit'])) 
    { 
     $act=trim($_POST['param_action']); 
     $about_us=$_POST['cms_description'];   

     if($act=="add") 
     { 
      $res=$con->get_data("select count(*) as cnt from cms"); 
      $cnt_cmt=mysql_result($res, 'cnt'); 

      if($cnt_cmt==0) 
      { 
       $flag=$con->iud("insert into cms (about_us)values('".mysql_real_escape_string(urlencode($about_us))."')");    
      } 
      else 
      { 
       $flag=$con->iud("update cms set about_us='".mysql_real_escape_string(urlencode($about_us))."'"); 
      } 

      if($flag==1) 
      { 
       $msg="Insertion done successfully.";   
      } 
      else if($flag==0) 
      { 
       $msg="Insertion failed - reason : ".mysql_errno()." : ".mysql_error(); 
      } 
     } 
     else if($act=="edit") 
     { 
      $cms_id=$_POST['cms_id']; 
      $flag=$con->iud("update cms set about_us='".mysql_real_escape_string(urlencode($about_us))."' where id=".$cms_id."");    
      if($flag==1) 
      { 
       $msg="About us has been updated successfully."; 
      } 
      else if($flag==0) 
      { 
       $msg="Updation failed - reason : ".mysql_errno()." : ".mysql_error(); 
      }   
     } 
    }   
    else if(isset($_GET['ed_id'])) 
    { 
     $ed_res=$con->get_data("select about_us from cms where id=".$_GET['ed_id'].""); 

     while($row=mysql_fetch_assoc($ed_res)) 
     { 
      $ed_about_us=$row['about_us'];  
     } 
    } 
    else if(isset($_GET['del_id'])) 
    { 
     $flag=$con->iud("update cms set about_us='' where id=".$_GET['del_id']); 
     if($flag==1) 
     { 
      $msg="About us been deleted successfully."; 
     } 
     else if($flag==0) 
     { 
      $msg="Can not delete - reason : ".mysql_errno()." : ".mysql_error();  
     } 
    } 
    else if(isset($_POST['btnDelete'])) 
    { 
     $set_del=$_POST['setDel']; 
     $flag=$con->iud("update cms set about_us='' where id in($set_del)"); 
     $size=sizeof(split(",", $set_del)); 

     if($flag==1) 
     { 
      if($size==1) 
      { 
       $msg="1 row deleted."; 
      } 
      else 
      { 
       $msg=$size." rows deleted.";  
      }   
     } 
     else if($flag==0) 
     { 
      $msg="Can not perform deletion - reason : ".mysql_errno()." : ".mysql_error(); 
     }  
    } 
?> 

    <?php include("tamplate/Template1.php");?> 
     <h2>About Us</h2> 
    <?php include("tamplate/NewTemplate.php");?> 

    <?php 
     if($flag==1) 
     {   
      echo "<p>"; 
      ?> 
       <!--[if !IE]>start system messages<![endif]--> 
       <ul class="system_messages">          
        <li class="green"><span class="ico"></span><strong class="system_title"><?php echo $msg; ?></strong></li>      
       </ul> 
       <!--[if !IE]>end system messages<![endif]--> 
      <?php    
      echo "</p>"; 
     } 
     else if($flag==0) 
     {  
      echo "<p>"; 
      ?> 
       <!--[if !IE]>start system messages<![endif]--> 
       <ul class="system_messages">      
        <li class="red"><span class="ico"></span><strong class="system_title"><?php echo $msg; ?></strong></li>           
       </ul> 
       <!--[if !IE]>end system messages<![endif]--> 
      <?php    
      echo "</p>";  
     } 
    ?> 
<img alt=\"\" src="/ckfinder/userfiles/images/1243_SS_2502.jpg" style=\"width: 490px; height: 618px;\" /> 
     <!--[if !IE]>start forms<![endif]--> 
    <form action="<?php $_SERVER['PHP_SELF']; ?>" id="dataForm" name="dataForm" method="post" class="search_form general_form"> 
     <!--[if !IE]>start fieldset<![endif]--> 
     <fieldset> 
      <!--[if !IE]>start forms<![endif]--> 
      <div class="forms"> 

      <!--[if !IE]>start row<![endif]--> 
      <div class="row"> 
      <?php 
       $ckeditor = new CKEditor(); 
       $ckeditor->basePath = 'ckeditor/'; 
       $ckeditor->config['filebrowserBrowseUrl'] = 'ckfinder/ckfinder.html'; 
       $ckeditor->config['filebrowserImageBrowseUrl'] = 'ckfinder/ckfinder.html?type=Images'; 
       $ckeditor->config['filebrowserFlashBrowseUrl'] = 'ckfinder/ckfinder.html?type=Flash'; 
       $ckeditor->config['filebrowserUploadUrl'] = 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files'; 
       $ckeditor->config['filebrowserImageUploadUrl'] = 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images'; 
       $ckeditor->config['filebrowserFlashUploadUrl'] = 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash'; 
       $ckeditor->editor('cms_description', urldecode($ed_about_us)); 

      ?>    

      <!--[if !IE]>start row<![endif]--> 
      <div class="row"> 
       <div class="buttons">                                     
         <span class="button send_form_btn"><span><span>Submit</span></span><input type="submit" value="Submit" id="btnSubmit" name="btnSubmit" onclick="return validate();"></span>      
       </div> 
      </div> 
      <!--[if !IE]>end row<![endif]--> 
      </div> 
     </fieldset> 

     <!--[if !IE]>end fieldset<![endif]-->     
     <input type="hidden" id="param_action" name="param_action" value=" 

      <?php 
       if(isset($_GET['ed_id'])) 
       { 
        echo "edit";   
       } 
       else 
       { 
        echo "add"; 
       } 
      ?> 
      " /> 

      <input type="hidden" id="cms_id" name="cms_id" value="<?php echo isset($_GET['ed_id'])?$_GET['ed_id']:"";?>" />    
    </form>    

    <?php include("tamplate/Template2.php");?> 
     <h2>About Us</h2> 
    <?php include("tamplate/NewTemplate1.php");?> 


    <form action="<?php echo $_SERVER['PHP_SELF'];?>" id="mainForm" name="mainForm" method="post">             

     <?php include("tamplate/ExtraTemplate.php");?>  

      <table cellpadding="0" cellspacing="0" width="100%"> 
       <tbody> 
       <th style="width: 10px;">Check</th> 
       <th style="width: 450px;">About Us</th>     
       <th style="width: 10px;">Actions</th> 

       <?php 

        $get_data=$con->get_data("select id, about_us from cms order by id"); 
        $cnt=1;$flag=''; 

        while($data_row=mysql_fetch_assoc($get_data)) 
        { 
         extract($data_row); 
         $cnt%2==0?$flag="second":$flag="first"; 
         ++$cnt; 

         echo "<tr class='$flag'>"; 
         echo "<td><input type='checkbox' name='chk' value='$id'></td>"; 
         echo "<td>".urldecode($about_us)."</td>"; 

         echo "<td><div class='actions'><ul><li><a href='".$_SERVER['PHP_SELF']."?ed_id=$id' class='action2'></a></li>"; 
         echo "<li><a href='".$_SERVER['PHP_SELF']."?del_id=$id&table_name=cms&pri=id' onclick='return deleteSingle($id);' class='action4'></a></li></ul></div></td>"; 
         echo "</tr>"; 
        } 
       ?> 

       </tbody> 
      </table>  
      <input type='hidden' id='setDel' name='setDel'/> 
      <?php include("tamplate/Template3.php");?>   
    </form> 
    <?php include("tamplate/Template4.php");?> 
</body> 
</html> 

回答

1

你嘗試使用html_entity_decode()顯示的內容?它將解碼編碼的html以獲得更好的輸出。參考here

編輯
更改查詢到以下

insert into cms (about_us) values ('".mysql_real_escape_string(urlecode(stripslashes($about_us)))‌​."')

當你從數據庫中獲取它,它使用

urldecode($value)

哪裏$value是你得到了塊從數據庫。

+0

試過但無濟於事。它顯示'\"\"',但它需要像'',用'\\'轉義'''是被禁止的。早些時候我使用了FCKEditor,其中有一個像'$ FCKeditorObj-> CreateHtml()'這樣的直接方式,我發現在CKEditor的情況下,雖然它應該在那裏,但是我認爲,你知道嗎? – Tiny

+0

它看起來像在塊存儲在數據庫中之前,它正在轉義引號,嘗試'urlencode()',然後轉義並存儲當你回來'urldecode()' – Deepak

+0

然後它顯示'%253Cp%253E%250D%250A%2509%253Cimg%2Balt%253D%255C%2522%255C%2522%2Bsrc%253D%255C% 2522%252Fckfinder%252Fuserfiles%252Fimages%252F1243_SS_2502.jpg%255℃%2522%2Bstyle%253D%255℃%2522width%253A%2B490px%253B%2Bheight%253A%2B618px%253B%255℃%2522%2B%252F%253E%253C% 252Fp%253E%250D%250A'。 – Tiny

相關問題