function upload($imgsdir) { if ($_FILES['newImage']['size'] !== 0) { $name = basename($_POST['newImageName'] == '' ? strtolower($_FILES['newImage']['name']) : strtolower($_POST['newImageName']), '.jpg'); $fName = $imgsdir . '/' . $name . '.jpg'; createDirsInPath($fName); if (move_uploaded_file($_FILES['newImage']['tmp_name'], $fName)) { $result = "The file <b>" . $fName . "</b> has been uploaded <br />"; $result .= createThumb($fName); } else { $result = "There was an error uploading the file for:{$name}, please try again!"; } return $result; } }
function generate($download, $template = '_pages/_commercials.html') { $tmp = '_tmp/Pefi_COMRES/'; $retVal = ''; createDirsInPath($tmp); if ($download) { $retVal .= downloadCommercialResZip($tmp); } else { $retVal .= '<p>Did not ask for Zip download...</p>'; } // hopefully there is only one file... TODO rethink $zip_files = discoverFiles($tmp, '.zip'); if (count($zip_files) == 0) { $retVal .= "<p>No zip file in dir: {$tmp}</p>"; } else { $zip = new ZipArchive(); $retValVal = $zip->open($zip_files[0]); $zip->extractTo($tmp); $zip->close(); $files = discoverFiles($tmp . 'tmp', '.html'); $retVal .= '<p>NrOfComResFiles in zip-dir:' . count($files) . "</p>"; $urls = explode(';', tr('commercials.urls:admin')); $retVal .= '<p>NrOfComResURLs in commercials.urls:' . count($urls) . "</p>"; $i = 0; foreach ($files as $file) { if ($i < count($urls)) { $fName = '_pages/' . $urls[$i++]; $f = fopen($fName, 'w'); fwrite($f, "\n<?php \$content = function () { ?>\n"); fwrite($f, change_strings($file)); fwrite($f, "\n<?php } ?>\n"); fwrite($f, "\n<?php include '{$template}'; ?>\n"); fclose($f); $retVal .= "<p>Created file: {$fName} </p>"; } else { $retVal .= '<p>------ Attention sizes of files in zip from outside source is different than number of URLs! ------</p>'; } } } return $retVal; }
public function cacheSmallTables($force = false) { $caD = $this->getCacheDir(); $ts = array_keys(static::$small_tables); if (!file_exists($caD . $this->db_pref . $ts[0] . '.php') || $force) { createDirsInPath($caD); foreach (static::$small_tables as $table => $pKey) { $this->cacheTable($this->db_pref . $table, $pKey); } return true; } else { return false; } }
function reset() { $fName = $this->fileName; return $this->semafore(function () use($fName) { if (is_file($fName)) { @unlink($fName); } createDirsInPath($fName); $fp = fopen($fName, 'w'); fclose($fp); }); }
function createThumb($fName, $outDir = 'thumbs', $thumbSize = 100, $suf = '', $ext = '.jpg') { // parse path for the extension $info = pathinfo($fName); // continue only if this is a JPEG image if (strtolower($info['extension']) == 'jpg') { // load image and get image size $img = imagecreatefromjpeg($fName); $width = imagesx($img); $height = imagesy($img); // calculate thumbnail size if ($width >= $height) { $new_width = $thumbSize; $new_height = floor($height * ($thumbSize / $width)); } else { $new_height = $thumbSize; $new_width = floor($width * ($thumbSize / $height)); } // create a new temporary image $tmp_img = imagecreatetruecolor($new_width, $new_height); // copy and resize old image into new image imagecopyresized($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height); // save thumbnail into a file $fName = dirname($fName) . '/' . $outDir . '/' . basename($fName, '.jpg') . $suf . $ext; createDirsInPath($fName); imagejpeg($tmp_img, $fName); return "Created thumb: {$fName} <br>"; } return "Not a jpg?: {$fName} <br>"; }