public function addPicture($el, $params) { // $ret = 0; $allowed = array('.gif','.jpg','.png'); $fileext=strtolower(substr($el->filename, strrpos($el->filename,"."))); // get original file extension $params->fileext = $fileext; if (in_array($fileext,$allowed)) { // now we will check it and create the thumbnail from big (or maybe small) source image $image = new SimpleImage(); // instantiate image manipulation class $image->load($el->tmp_name); // load source image if ($image->getHeight()>0) { // if it's a good image file - proceed mkdirr($this->settings->photofolder."/".$params->id); $thisid = (int)$this->addGalleryItem($params); // echo("ID: ".$thisid); $filename = $this->settings->photofolder."/".$params->id."/".$thisid.$fileext; // build filename $filenamethb = $this->settings->photofolder."/".$params->id."/thb_".$thisid.$fileext; // build thumbnail filename $filenamepre = $this->settings->photofolder."/".$params->id."/pre_".$thisid.$fileext; // build thumbnail filename if (file_exists($filename) ) unlink($filename ); if (file_exists($filenamethb)) unlink($filenamethb); if (file_exists($filenamepre)) unlink($filenamepre); move_uploaded_file($el->tmp_name, $filename)."<br>"; if (($image->getHeight()>$this->settings->previewheight) || ($image->getWidth()>$this->settings->previewwidth)) { $image->resizepic( $this->settings->previewwidth, $this->settings->previewheight ); // resize to height as desired in technical requirements $image->save($filenamepre); // save resized file to disk } else { copy($filename, $filenamepre); } echo "Success"; $image->load($filename); // load source image $image->resizepic( $this->settings->thumbwidth, $this->settings->thumbheight ); // resize to height as desired in technical requirements $image->save($filenamethb); // save resized file to disk // $el->fname = $el->id.$fileext."?e=".rand(0,99999); // we attach "e=" parameter here to force the web browser to update its cache (otherwise the photo may not be updated) // $el->id=$this->db->saveElementData($el); // save filename to database (we must do it because of various file extensions possible: GIF, JPG, PNG) } else { // possible attack unlink($el->tmp_name); // delete file } // echo $filename."<br>"; } // echo $ret; }
public function open($savePath, $sessionName) { // $this->savePath = $savePath; $this->id = session_id(); $this->sessionName = $sessionName; if (!is_dir($this->savePath)) { @mkdirr($this->savePath, 0777); } @chmod($this->savePath, 0777); // echo $this->savePath; if (file_exists($this->savePath.'/sess_'.$this->id)) { $sessiondata = file_get_contents ($this->savePath.'/sess_'.$this->id); // open file containing session data session_decode($sessiondata); // Decode the session data } return true; }
public function mkdirr($pn, $mode = null) { if (is_dir($pn) || empty($pn)) { return true; } $pn = str_replace(array('/', ''), DIRECTORY_SEPARATOR, $pn); if (is_file($pn)) { trigger_error('mkdirr() File exists', E_USER_WARNING); return false; } $next_pathname = substr($pn, 0, strrpos($pn, DIRECTORY_SEPARATOR)); if (mkdirr($next_pathname, $mode)) { if (!file_exists($pn)) { return mkdir($pn, $mode); } } return false; }
/** * Create a directory structure recursively * * @author Aidan Lister <*****@*****.**> * @version 1.0.2 * @link http://aidanlister.com/2004/04/recursively-creating-directory-structures/ * @param string $pathname The directory structure to create * @return bool Returns TRUE on success, FALSE on failure */ function mkdirr($pathname, $mode = 0777) { // Check if directory already exists if (is_dir($pathname) || empty($pathname)) { return true; } // Ensure a file does not already exist with the same name $pathname = str_replace(array('/', ''), DIRECTORY_SEPARATOR, $pathname); if (is_file($pathname)) { trigger_error('mkdirr() File exists', E_USER_WARNING); return false; } // Crawl up the directory tree $next_pathname = substr($pathname, 0, strrpos($pathname, DIRECTORY_SEPARATOR)); if (mkdirr($next_pathname, $mode)) { if (!file_exists($pathname)) { return mkdir($pathname, $mode); } } return false; }
/** * Create a directory structure recursively * * @author Aidan Lister <*****@*****.**> * @version 1.0.0 * @param string $pathname The directory structure to create * @return bool Returns TRUE on success, FALSE on failure */ function mkdirr($pathname, $mode = null) { // Check if directory already exists if (is_dir($pathname) || empty($pathname)) { return true; } // Ensure a file does not already exist with the same name if (is_file($pathname)) { trigger_error('mkdirr() File exists', E_USER_WARNING); return false; } // Crawl up the directory tree $next_pathname = substr($pathname, 0, strrpos($pathname, DIRECTORY_SEPARATOR)); if (mkdirr($next_pathname, $mode)) { if (!file_exists($pathname)) { //changed the following 4 lines to allow custom permissions $old = umask(0); $returnValue = mkdir($pathname, $mode); umask($old); return $returnValue; } } return false; }
public function addToLogPDOErrors($sql, $message) { @mkdirr('data/logs'); file_put_contents('data/logs/PDOErrors.txt', date("Y-m-d H:i:s")."\t".$sql."\t".$message."\n", FILE_APPEND); // write to log in case of errors }
function addtolog($txt) { @mkdirr('data/logs'); file_put_contents('data/logs/events.txt', (date("Y-m-d H:i:s"))."\t".$txt, FILE_APPEND); // write to log in case of errors // echo $txt."<br>"; }
function moveUploads($action, $json) { $rslt = 0; switch ($action) { case ('steps'): $src_dir = $this->settings->temppath."/"; $dst_dir = $this->settings->projectspath."/"; $id = session_id(); mkdirr($dst_dir); $dir = sdir($src_dir, "full_".$id."_*.*",1); // ajax_echo_r ($dir); if (sizeof($dir)) { foreach ($dir as $filef) { $filet = str_replace("full_","thb_",$filef); $filedstf = str_replace(session_id(),$json->ProjectID."_".$json->StepID,$filef); $filedstt = str_replace(session_id(),$json->ProjectID."_".$json->StepID,$filet); // echo $src_dir.$filef."-".$dst_dir.$filedst."<br>"; $rslt+=rename($src_dir.$filef, $dst_dir.$filedstf); $rslt+=rename($src_dir.$filet, $dst_dir.$filedstt); } } break; } return $rslt; }
/** Function to unzip $file in $dir to $destination with $permissions * * modified candido1212 at yahoo dot com dot br's code on php.net manual * http://us3.php.net/zip * @param path, filename, destination, permissions (refer to mkdir) */ function unzip($dir, $file, $destination = "", $permissions = 0755) { if (substr($dir, -1) != DIRECTORY_SEPARATOR) { $dir .= DIRECTORY_SEPARATOR; } if (substr($destination, -1) != DIRECTORY_SEPARATOR) { $destination .= DIRECTORY_SEPARATOR; } $path_file = $dir . $file; $zip = zip_open($path_file); $_tmp = array(); if ($zip) { while ($zip_entry = zip_read($zip)) { if (zip_entry_open($zip, $zip_entry, "r")) { if ($destination) { $path_file = $destination . zip_entry_name($zip_entry); } else { $path_file = $dir . zip_entry_name($zip_entry); } $new_dir = dirname($path_file); // Create Recursive Directory mkdirr($new_dir, $permissions); //change: do not try to read file if is a directory if (!(substr(zip_entry_name($zip_entry), -1) == "/")) { $fp = fopen($path_file, "w"); while ($buf = zip_entry_read($zip_entry, 4096)) { fwrite($fp, $buf, 4096); } fclose($fp); $_tmp[] = $path_file; } zip_entry_close($zip_entry); } } zip_close($zip); } return $_tmp; }
function eraseCacheSecure($id) { $path = getCacheDir(); @mkdirr ($path); return unlink($path.$id."&".session_id().".dat"); }
/** * Create a directory. If a multiple depth, will recursively * call itself * * @param string $name * @return boolean */ public function createDirectory($name) { $this->log->debug("Creating folder {$name}"); return mkdirr($this->fileRoot . $this->normalizePath($name), 0775); }
function Unzip($dir, $file, $destiny = "") { $dir .= DIRECTORY_SEPARATOR; $path_file = $dir . $file; $zip = zip_open($path_file); $_tmp = array(); $count = 0; if ($zip) { while ($zip_entry = zip_read($zip)) { $_tmp[$count]["filename"] = zip_entry_name($zip_entry); $_tmp[$count]["stored_filename"] = zip_entry_name($zip_entry); $_tmp[$count]["size"] = zip_entry_filesize($zip_entry); $_tmp[$count]["compressed_size"] = zip_entry_compressedsize($zip_entry); $_tmp[$count]["mtime"] = ""; $_tmp[$count]["comment"] = ""; $_tmp[$count]["folder"] = dirname(zip_entry_name($zip_entry)); $_tmp[$count]["index"] = $count; $_tmp[$count]["status"] = "ok"; $_tmp[$count]["method"] = zip_entry_compressionmethod($zip_entry); if (zip_entry_open($zip, $zip_entry, "r")) { $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)); if ($destiny) { $path_file = str_replace("/", DIRECTORY_SEPARATOR, $destiny . zip_entry_name($zip_entry)); } else { $path_file = str_replace("/", DIRECTORY_SEPARATOR, $dir . zip_entry_name($zip_entry)); } $new_dir = dirname($path_file); // Create Recursive Directory mkdirr($new_dir); $fp = fopen($dir . zip_entry_name($zip_entry), "w"); fwrite($fp, $buf); fclose($fp); zip_entry_close($zip_entry); } echo "\n</pre>"; $count++; } zip_close($zip); } }
$now = date("Y.m.d.h.i.s"); $ret = "Update date and time: ".$now.$PHP_EOL; $za = new ZipArchive(); $za->open('update.zip'); for( $i = 0; $i < $za->numFiles; $i++ ){ $stat = $za->statIndex( $i ); if (file_exists($stat['name'])) { @mkdirr ("backups"); $ret.="Creating backup: ".$stat['name'].$PHP_EOL; if (substr_count($stat['name'],"/")>0) { $subpath = substr($stat['name'],0, strrpos($stat['name'],"/")); // $ret.="Subfolder: ".$subpath.$PHP_EOL; @mkdirr ("backups/".$subpath); } $ret.=((rename($stat['name'],"backups/".$stat['name'].".".$now.".bak"))?"Successful":"Failed").$PHP_EOL; } else { $ret.="Cannot create backup: ".$stat['name']." - file not found!".$PHP_EOL; } } $ret.="Extracting to ".$thisfolder.$PHP_EOL; $za->extractTo($thisfolder); // print_r($_SERVER); $za->close(); if (file_exists('revision.ver')) { $c = (int)file_get_contents('revision.ver');
public function import() { // import functionality to get data from ISCentre addtolog("Controller import begin"); include_once ("controller/DBImport.php"); $this->dbimport = new DBImport($this->settings); // instantiate a class $action = getvariablereq ('action'); // get action from the request $data = getvariablereq ('data' ); // get JSON data from the request $data = str_replace('\"','"',$data); // fix some escaped paths (if any) $mtime = microtime(true); $thisfolder = substr($_SERVER['DOCUMENT_ROOT'].$_SERVER['SCRIPT_NAME'],0,strrpos($_SERVER['DOCUMENT_ROOT'].$_SERVER['SCRIPT_NAME'] ,"/"))."/data/temp/dbupdate"; @mkdirr ($thisfolder); switch ($action) { case ('update'): $this->dbimport->importtables($thisfolder); echo "Job done\n"; break; default: if (sizeof($_FILES)>0) { foreach ($_FILES as $file) { if (file_exists($thisfolder."/".$file['name'])) { unlink($thisfolder."/".$file['name']); } move_uploaded_file ($file['tmp_name'],$thisfolder."/".$file['name']); echo "File accepted"; } } break; } $fieldid = array(); addtolog("Controller import end"); }
function addtologEx($txt, $fname = 'events.txt') { @mkdirr('data/logs'); file_put_contents('data/logs/'.$fname, (date("Y-m-d H:i:s"))."\t".print_r($txt, true)."\n", FILE_APPEND); // write to log in case of errors // ajax_echo_r ($txt); }
function backup() { // $sql = "show tables;"; // $tables = $this->db->query_flat($sql); $tables = array('objects', 'customers', 'users'); // ajax_echo_r ($tables); $timestamp = date("Y-m-d-H-i-s"); $dir = "data/backups"; mkdirr(getrootdirsrv().$dir); $filename = getrootdirsrv().$dir."/izum-rel-".$timestamp.".xls"; $filename_client = getrootdir() .$dir."/izum-rel-".$timestamp.".xls"; $output = new PHPExcel; // Create new PHPExcel object $output->getProperties()->setCreator("Izum by Creative Force") ->setLastModifiedBy("Izum by Creative Force") ->setTitle("Izum Backup File - ".date("Y-m-d H:i:s")) ->setSubject("Office 2007 XLS Test Document") ->setDescription("Test document for Office 2007 XLS, generated using PHP classes.") ->setKeywords("Creative Force Izum backup") ->setCategory("Test result file"); $i = 0; $n = 1; $si = 0; $srcrow = array(); foreach ($tables as $tableName) { // $tableName = 'accounts'; // ajax_echo_r ($tableName); if (!in_array($tableName, array('visits', 'events'))) { $sql = "SELECT * FROM `".$tableName."` ORDER BY `DateAdded`;"; $ret = $this->db->query_first($sql); $col=0; if ($si) { // Add new sheet $output->createSheet($si)->setTitle($tableName); //Setting index when creating } else { $output->setActiveSheetIndex($si)->setTitle($tableName); } $colnames = getColNames(); foreach (array_keys((array)$ret) as $itm) { // for ($col=0; $col<$colCount; $col++) { // echo $itm; if ($colnames[$itm]) { $itm = $colnames[$itm]; } else { // echo $itm."-"; } $output->setActiveSheetIndex($si)->setCellValueByColumnAndRow($col, 1, $itm); // $srcrow[] = $xls->getCellByColumnAndRow($col,2)->getValue(); $col++; } // $colnames = getColNames(); $i=2; $sql = "SELECT * FROM `".$tableName."`;"; $ret = $this->db->query($sql); $subtables = array('districts' , 'customersubtypes' , 'methodsofpayment' , 'sources' , 'users' , 'directions' , 'housetypes' , 'markets' , 'mediators' , 'overlappingtypes' , 'layouttypes' , 'toilettypes' , 'conditions' , 'finishings' , 'floorsurfaces' , 'stovetypes' , 'doorstypes' , 'wallssurfaces' , 'wallsmaterials' , 'bathroomequipments' , 'windowstypes' , 'rightssources' , 'rightstransmissions' ); $subcolumns = array('DistrictID', 'CustomerSubtypeID', 'MethodOfPaymentID', 'SourceID', 'UserID', 'DirectionID', 'HouseTypeID', 'MarketID', 'MediatorID', 'OverlappingTypeID', 'LayoutTypeID', 'ToiletTypeID', 'ConditionID', 'FinishingID', 'FloorSurfaceID', 'StoveTypeID', 'DoorsTypeID', 'WallsSurfaceID', 'WallsMaterialID', 'BathroomEquipmentID', 'WindowsTypeID', 'RightsSourceID', 'RightsTransmissionID'); $ret = $this->fillSubtables($ret, $subtables, $subcolumns); // ajax_echo_r ($ret); // return false; foreach ($ret as $itm) { $col=0; $thisrecord = $this->cache[(string)$id]; foreach ($itm as $c) { $output->setActiveSheetIndex($si)->setCellValueByColumnAndRow($col, $i, $c); $col++; } $i++; } } $si++; } $output->setActiveSheetIndex(0); $objWriter = PHPExcel_IOFactory::createWriter($output, 'Excel5'); $objWriter->save($filename); return ($filename_client); /* $tableName = 'accounts'; $sql = "SELECT * FROM `".$tableName."`;"; $ret = $this->db->query_first($sql); ajax_echo_r ($ret); $buf = "INSERT INTO `` "; foreach (array_keys((array)$ret as $itm) { } // file_put_contents ($backupFile, implode())."\n", FILE_APPEND); $sql = "SELECT * FROM `".$tableName."`;"; $r = $this->db->query($sql); ajax_echo_r ($r); */ }
static function unzip($dir, $file) { $zip = zip_open(realpath($dir) . "/" . $file); if (!$zip) { return "Unable to proccess file '{$file}'"; } $zfile = 'word/document.xml'; while ($zip_entry = zip_read($zip)) { $zdir = dirname(zip_entry_name($zip_entry)); $zname = zip_entry_name($zip_entry); if (!zip_entry_open($zip, $zip_entry, "r")) { $e .= "Unable to proccess file '{$zname}'"; continue; } if (!is_dir($zdir)) { mkdirr($zdir, 0777); } $zip_fs = zip_entry_filesize($zip_entry); if (empty($zip_fs)) { continue; } $zz = zip_entry_read($zip_entry, $zip_fs); if ($zname == $zfile) { return $zz; } //$z=fopen($zname,"w"); //fwrite($z,$zz); //fclose($z); zip_entry_close($zip_entry); } zip_close($zip); return $e; }