Ignore:
Timestamp:
09/05/05 07:23:55 (14 years ago)
Author:
gocher
Message:

now the InsertPicture? plugin only use the relativ webpath to the picturefolder and the default is /xinha/plugins/InsertPicture/demo_pictures/

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/plugins/InsertPicture/InsertPicture.php

    r304 r307  
    11<?PHP 
    2   $PicturePath = $_REQUEST['picturepath']; 
    3   $LocalPicturePath = $_REQUEST['localpicturepath']; 
     2  //this plugin only use the relativ webpath to the picturefolder 
     3  //default ~  /htmlarea/plugins/InsertPicture/demo_pictures/ 
     4  strstr( PHP_OS, "WIN") ? $strPathSeparator = "\\" : $strPathSeparator = "/"; 
     5  if (isset($_REQUEST['picturepath'])) { 
     6    $getRequest = true; 
     7    $PicturePath = 'http://'.$_SERVER['HTTP_HOST'].$_REQUEST['picturepath']; 
     8    //$LocalPicturePath = $_REQUEST['localpicturepath']; 
     9 
     10    $AInsertPicturePath = explode ('/', 'http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/demo_pictures/'); 
     11    $ALocalInsertPicturePath = explode($strPathSeparator, dirname(__FILE__).$strPathSeparator.'demo_pictures'); 
     12    $APicturePath = explode('/', 'http://'.$_SERVER['HTTP_HOST'].$_REQUEST['picturepath']); 
     13 
     14    $AtheFilePath = array_values (array_diff ($APicturePath, $AInsertPicturePath)); 
     15    $theFilePath = implode($strPathSeparator, $AtheFilePath).$strPathSeparator; 
     16 
     17    $AtheRootPath = array_values (array_diff ($ALocalInsertPicturePath, $AInsertPicturePath)); 
     18    $theRootPath = implode($strPathSeparator, $AtheRootPath); 
     19 
     20    $LocalPicturePath = $theRootPath.$strPathSeparator.$theFilePath.$strPathSeparator; 
     21  } else { 
     22    $getRequest = false; 
     23    $PicturePath =  'http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/demo_pictures/'; 
     24    $LocalPicturePath = dirname(__FILE__).$strPathSeparator.'demo_pictures'; 
     25  } 
    426  $limitedext = array(".gif",".jpg",".png",".jpeg"); //Extensions you want files uploaded limited to. 
    5         $limitedsize = "1000000"; //size limit in bytes 
    6         $message = ""; 
     27  $limitedsize = "1000000"; //size limit in bytes 
     28  $message = ""; 
    729  function formatSize($size)  
    8         { 
    9                 if($size < 1024)  
    10                         return $size.' bytes';   
    11                 else if($size >= 1024 && $size < 1024*1024)  
    12                         return sprintf('%01.2f',$size/1024.0).' Kb';     
    13                 else 
    14                         return sprintf('%01.2f',$size/(1024.0*1024)).' Mb';      
    15         } 
    16  
    17         if (isset($_FILES['file'])) { 
     30  { 
     31    if($size < 1024)  
     32      return $size.' bytes';     
     33    else if($size >= 1024 && $size < 1024*1024)  
     34      return sprintf('%01.2f',$size/1024.0).' Kb';       
     35    else 
     36      return sprintf('%01.2f',$size/(1024.0*1024)).' Mb';        
     37  } 
     38 
     39  if (isset($_FILES['file'])) { 
    1840    $file = $_FILES['file']; 
    19                 $ext = strrchr($file['name'],'.'); 
    20                 if (!in_array($ext,$limitedext)) { 
     41    $ext = strrchr($file['name'],'.'); 
     42    if (!in_array($ext,$limitedext)) { 
    2143      $message = "The file you are uploading doesn't have the correct extension."; 
    22     } 
    23                 else if (file_exists($LocalPicturePath.'\\'.$file['name'])) { 
     44    } else if (file_exists($LocalPicturePath.'\\'.$file['name'])) { 
    2445      $message = "The file you are uploading already exists."; 
    25     } 
    26                 else if ($file['size'] > $limitedsize) { 
     46    } else if ($file['size'] > $limitedsize) { 
    2747      $message = "The file you are uploading is to big. The max Filesize is</span><span> ".formatSize($limitedsize)."."; 
    28     } 
    29                 else { 
    30       copy($file['tmp_name'], $LocalPicturePath.'\\'.$file['name']); 
    31                 }        
    32         } 
     48    } else { 
     49      copy($file['tmp_name'], $LocalPicturePath.$strPathSeparator.$file['name']); 
     50    } 
     51  } 
    3352 
    3453?> 
     
    4968 
    5069function Init() { 
    51         __dlg_translate("InsertPicture"); 
     70  __dlg_translate("InsertPicture"); 
    5271  __dlg_init(); 
    5372  window.resizeTo(470, 490); 
     
    93112}; 
    94113 
     114function onUpload() { 
     115  var required = { 
     116    "file": i18n("Please select a file to upload.") 
     117  }; 
     118  for (var i in required) { 
     119    var el = document.getElementById(i); 
     120    if (!el.value) { 
     121      alert(required[i]); 
     122      el.focus(); 
     123      return false; 
     124    } 
     125  } 
     126  submit(); 
     127  return false; 
     128} 
     129 
    95130function onCancel() { 
    96131  __dlg_close(null); 
     
    133168  <tr> 
    134169    <td>Images on the Server:<br> 
    135                 <?php //echo $PicturePath.'<br>'.$LocalPicturePath ?> 
    136170    <select value="" style="width:200" size="10" onClick="CopyToURL(this[this.selectedIndex].value);"> 
    137171<?php 
    138         $d = @dir($LocalPicturePath); 
    139         while (false !== ($entry = $d->read())) //not a dot file or directory 
    140         {       if(substr($entry,0,1) != '.') 
    141                 { echo '<OPTION value="' . $PicturePath.$entry. '">' . $entry . '(' . formatSize(filesize($LocalPicturePath.'\\'.$entry)) .')</OPTION>'; 
    142                 } 
    143         } 
    144         $d->close(); 
     172  $d = @dir($LocalPicturePath); 
     173  while (false !== ($entry = $d->read())) { //not a dot file or directory 
     174    if(substr($entry,0,1) != '.') {  
     175      echo '<OPTION value="' . $PicturePath.$entry. '">' . $entry . '(' . formatSize(filesize($LocalPicturePath.'\\'.$entry)) .')</OPTION>'; 
     176    } 
     177  } 
     178  $d->close(); 
    145179?> 
    146180    </select> 
    147  
    148       <form method="post" action="<?php echo $_SERVER['PHP_SELF'].'?picturepath=' . $PicturePath. '&localpicturepath=' . $LocalPicturePath?>" enctype="multipart/form-data"> 
    149         <input type="file" name="file" size="30"><br> 
    150                                 <button type="submit" name="ok" onclick="return submit();">Upload file</button><br> 
    151                                 <span><?php echo $message ?></span> 
     181<?php 
     182  if ($getRequest == true) { 
     183    echo '<form method="post" action="'.$_SERVER['PHP_SELF'].'?picturepath='.$_REQUEST['picturepath'].'" enctype="multipart/form-data">'; 
     184  } else { 
     185    echo '<form method="post" action="'.$_SERVER['PHP_SELF'].'" enctype="multipart/form-data">'; 
     186  } 
     187?> 
     188        <input type="file" name="file" id="file" size="30"><br> 
     189        <button type="submit" name="ok" onclick="return onUpload();">Upload file</button><br> 
     190        <span><?php echo $message ?></span> 
    152191      </form> 
    153192 
Note: See TracChangeset for help on using the changeset viewer.