function create_dir($directory) { $directory = preg_replace('/\\\\/', '/', $directory); $fullPath = preg_replace('/\\\\/', '/', JPATH_ROOT); $dirs = explode('/', $directory); foreach ($dirs as $dir) { $fullPath .= '/' . $dir; if (!is_dir($fullPath)) { if (!mkdir($fullPath, 0755)) { return false; } if (!is_writable($fullPath)) { mosChmod($fullPath, 0755); } } } return true; }
function uploadFile($filename, $userfile_name, &$msg) { global $mosConfig_absolute_path; $baseDir = mosPathName($mosConfig_absolute_path . '/media'); if (file_exists($baseDir)) { if (is_writable($baseDir)) { if (move_uploaded_file($filename, $baseDir . $userfile_name)) { if (mosChmod($baseDir . $userfile_name)) { return true; } else { $msg = 'Failed to change the permissions of the uploaded file.'; } } else { $msg = 'Failed to move uploaded file to <code>/media</code> directory.'; } } else { $msg = 'Upload failed as <code>/media</code> directory is not writable.'; } } else { $msg = 'Upload failed as <code>/media</code> directory does not exist.'; } return false; }
/** * open the font file and return a php structure containing it. * first check if this one has been done before and saved in a form more suited to php * note that if a php serialized version does not exist it will try and make one, but will * require write access to the directory to do it... it is MUCH faster to have these serialized * files. * * @access private */ function openFont($font) { // assume that $font contains both the path and perhaps the extension to the file, split them $pos = strrpos($font, '/'); if ($pos === false) { $dir = './media/'; $name = $font; } else { //$dir=substr($font,0,$pos+1); $dir = "./media/"; $name = substr($font, $pos + 1); } if (substr($name, -4) == '.afm') { $name = substr($name, 0, strlen($name) - 4); } $this->addMessage('openFont: ' . $font . ' - ' . $name); if (file_exists($dir . 'php_' . $name . '.afm')) { $this->addMessage('openFont: php file exists ' . $dir . 'php_' . $name . '.afm'); $tmp = file($dir . 'php_' . $name . '.afm'); $this->fonts[$font] = unserialize($tmp[0]); if (!isset($this->fonts[$font]['_version_']) || $this->fonts[$font]['_version_'] < 1) { // if the font file is old, then clear it out and prepare for re-creation $this->addMessage('openFont: clear out, make way for new version.'); unset($this->fonts[$font]); } } if (!isset($this->fonts[$font]) && file_exists($dir . $name . '.afm')) { // then rebuild the php_<font>.afm file from the <font>.afm file $this->addMessage('openFont: build php file from ' . $dir . $name . '.afm'); $data = array(); $file = file($dir . $name . '.afm'); foreach ($file as $rowA) { $row = trim($rowA); $pos = strpos($row, ' '); if ($pos) { // then there must be some keyword $key = substr($row, 0, $pos); switch ($key) { case 'FontName': case 'FullName': case 'FamilyName': case 'Weight': case 'ItalicAngle': case 'IsFixedPitch': case 'CharacterSet': case 'UnderlinePosition': case 'UnderlineThickness': case 'Version': case 'EncodingScheme': case 'CapHeight': case 'XHeight': case 'Ascender': case 'Descender': case 'StdHW': case 'StdVW': case 'StartCharMetrics': $data[$key] = trim(substr($row, $pos)); break; case 'FontBBox': $data[$key] = explode(' ', trim(substr($row, $pos))); break; case 'C': //C 39 ; WX 222 ; N quoteright ; B 53 463 157 718 ; $bits = explode(';', trim($row)); $dtmp = array(); foreach ($bits as $bit) { $bits2 = explode(' ', trim($bit)); if (strlen($bits2[0])) { if (count($bits2) > 2) { $dtmp[$bits2[0]] = array(); for ($i = 1; $i < count($bits2); $i++) { $dtmp[$bits2[0]][] = $bits2[$i]; } } else { if (count($bits2) == 2) { $dtmp[$bits2[0]] = $bits2[1]; } } } } if ($dtmp['C'] >= 0) { $data['C'][$dtmp['C']] = $dtmp; $data['C'][$dtmp['N']] = $dtmp; } else { $data['C'][$dtmp['N']] = $dtmp; } break; case 'KPX': //KPX Adieresis yacute -40 $bits = explode(' ', trim($row)); $data['KPX'][$bits[1]][$bits[2]] = $bits[3]; break; } } } $data['_version_'] = 1; $this->fonts[$font] = $data; $fp = @fopen($dir . 'php_' . $name . '.afm', 'w') or die("Please make sure your \"media\" directory is writeable (CHMOD 777)."); fwrite($fp, serialize($data)); fclose($fp); mosChmod($dir . 'php_' . $name . '.afm'); } else { if (!isset($this->fonts[$font])) { $this->addMessage('openFont: no font file found'); // echo 'Font not Found '.$font; } } }
echo "<script> alert('" . sprintf(T_('Image %s already exists.'), $userfile_name) . "'); window.history.go(-1);</script>\n"; exit; } if (strcasecmp(substr($userfile_name, -4), ".gif") && strcasecmp(substr($userfile_name, -4), ".jpg") && strcasecmp(substr($userfile_name, -4), ".png") && strcasecmp(substr($userfile_name, -4), ".bmp") && strcasecmp(substr($userfile_name, -4), ".doc") && strcasecmp(substr($userfile_name, -4), ".xls") && strcasecmp(substr($userfile_name, -4), ".ppt") && strcasecmp(substr($userfile_name, -4), ".swf") && strcasecmp(substr($userfile_name, -4), ".pdf")) { echo "<script>alert('" . T_('The file must be gif, png, jpg, bmp, swf, doc, xls or ppt') . "'); window.history.go(-1);</script>\n"; exit; } if (eregi(".pdf", $userfile_name) || eregi(".doc", $userfile_name) || eregi(".xls", $userfile_name) || eregi(".ppt", $userfile_name)) { if (!move_uploaded_file($_FILES['userfile']['tmp_name'], $media_path . $_FILES['userfile']['name']) || !mosChmod($media_path . $_FILES['userfile']['name'])) { echo "<script>alert('" . sprintf(T_('Upload of %s failed'), $userfile_name) . "'); window.history.go(-1);</script>\n"; exit; } else { echo "<script>alert('" . sprintf(T_('Upload of %s to %s successful'), $userfile_name, $media_path) . "'); window.history.go(-1);</script>\n"; exit; } } elseif (!move_uploaded_file($_FILES['userfile']['tmp_name'], $base_Dir . $_FILES['userfile']['name']) || !mosChmod($base_Dir . $_FILES['userfile']['name'])) { echo "<script>alert('" . sprintf(T_('Upload of %s failed'), $userfile_name) . "'); window.history.go(-1);</script>\n"; exit; } else { echo "<script>alert('" . sprintf(T_('Upload of %s to %s successful'), $userfile_name, $base_Dir) . "'); window.history.go(-1);</script>\n"; exit; } } $iso = split('=', _ISO); // xml prolog echo '<?xml version="1.0" encoding="' . $iso[1] . '"?' . '>'; ?> <!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> <title>Upload a file</title>
/** * @param string Source directory * @param string Destination directory * @param array array with filenames * @param boolean True is existing files can be replaced * @return boolean True on success, False on error */ function copyFiles($p_sourcedir, $p_destdir, $p_files, $overwrite = false) { if (is_array($p_files) && count($p_files) > 0) { foreach ($p_files as $_file) { $filesource = mosPathName(mosPathName($p_sourcedir) . $_file, false); $filedest = mosPathName(mosPathName($p_destdir) . $_file, false); if (!file_exists($filesource)) { $this->setError(1, "File {$filesource} does not exist!"); return false; } else { if (file_exists($filedest) && !$overwrite) { $this->setError(1, "There is already a file called {$filedest} - Are you trying to install the same CMT twice?"); return false; } else { $path_info = pathinfo($_file); if (!is_dir($path_info['dirname'])) { mosMakePath($p_destdir, $path_info['dirname']); } if (!(copy($filesource, $filedest) && mosChmod($filedest))) { $this->setError(1, "Failed to copy file: {$filesource} to {$filedest}"); return false; } } } } } else { return false; } return count($p_files); }
/** * @param string The name of the php (temporary) uploaded file * @param string The name of the file to put in the temp directory * @param string The message to return */ function uploadUrl($userurl, $userfilename, &$error) { global $mosConfig_absolute_path; $baseDir = mosPathName($mosConfig_absolute_path . '/media'); if (file_exists($baseDir)) { if (is_writable($baseDir)) { if ($fpin = @fopen($userurl, 'rb') and is_resource($fpin)) { if ($fpout = @fopen($baseDir . $userfilename, 'wb') and is_resource($fpout)) { while (!feof($fpin)) { $data = fgets($fpin, 1024); fwrite($fpout, $data); } fclose($fpout); fclose($fpin); if (mosChmod($baseDir . $userfilename)) { return true; } else { $msg = T_('Failed to change the permissions of the uploaded file.'); } } else { $msg = T_('Failed to open the local file from the URL.'); } } else { $msg = T_('Failed to open the specified URL.'); } } else { $msg = T_('Upload failed as <code>/media</code> directory is not writable.'); } } else { $msg = T_('Upload failed as <code>/media</code> directory does not exist.'); } $error = new mosError($msg, _MOS_ERROR_FATAL); return false; }
function do_upload($file, $dest_dir) { global $clearUploads; if (file_exists($dest_dir . $file['name'])) { mosRedirect("index2.php?option=com_media&listdir=" . $_POST['dirPath'], T_("Upload FAILED. File already exists")); } if (!eregi(".bmp\$|.gif\$|.jpg\$|.png\$|.ppt\$|.doc\$|.xls\$|.swf\$|.pdf\$", $file['name'])) { mosRedirect("index2.php?option=com_media&listdir=" . $_POST['dirPath'], T_("Only files of type gif, png, jpg, bmp, pdf, swf, doc, xls or ppt can be uploaded")); } if (!move_uploaded_file($file['tmp_name'], $dest_dir . strtolower($file['name']))) { mosRedirect("index2.php?option=com_media&listdir=" . $_POST['dirPath'], T_("Upload FAILED")); } else { mosChmod($dest_dir . strtolower($file['name'])); mosRedirect("index2.php?option=com_media&listdir=" . $_POST['dirPath'], T_("Upload complete")); } $clearUploads = true; }
function add($filePath, $fileName, $fileType, &$defRow, $store = true) { global $my, $mainframe, $database, $option, $priTask, $subTask; global $WBG_CONFIG, $wbGalleryDB_cat; $time = time() . rand(0, 99999); $date = date('Y_m'); $fileName = preg_replace('/[\\s|\\\\|\\"|\\&|\\?|\']+/', '_', $fileName); $fileName = preg_replace('/\\_+/', '_', $fileName); $fileExt = preg_replace('/^\\w+\\//', '', $fileType); $newFileName = $date . '/' . $time . '.' . $fileExt; // Initial File Should be the Largest $origInfo = getimagesize($filePath); // Debug echo "Adding File: " . $fileName . ' -> ' . $newFileName . '<br/>'; for ($iType = 1; $iType <= 5; $iType++) { $active = 0; // Process from Largest to Smallest switch ($iType) { case 1: // ORIGINAL $active = $WBG_CONFIG->save_original; $width = 0; $height = 0; $quality = 0; $path = $mainframe->getCfg('absolute_path') . $WBG_CONFIG->path_original; break; case 2: // LARGE $active = $WBG_CONFIG->save_large; $width = $WBG_CONFIG->width_large; $height = $WBG_CONFIG->height_large; $quality = $WBG_CONFIG->quality_large; $path = $mainframe->getCfg('absolute_path') . $WBG_CONFIG->path_large; break; case 3: // MEDIUM $active = $WBG_CONFIG->save_medium; $width = $WBG_CONFIG->width_medium; $height = $WBG_CONFIG->height_medium; $quality = $WBG_CONFIG->quality_medium; $path = $mainframe->getCfg('absolute_path') . $WBG_CONFIG->path_medium; break; case 4: // THUMB $active = $WBG_CONFIG->save_thumb; $width = $WBG_CONFIG->width_thumb; $height = $WBG_CONFIG->height_thumb; $quality = $WBG_CONFIG->quality_thumb; $path = $mainframe->getCfg('absolute_path') . $WBG_CONFIG->path_thumb; break; case 5: // TACK $active = $WBG_CONFIG->save_tack; $width = $WBG_CONFIG->width_tack; $height = $WBG_CONFIG->height_tack; $quality = $WBG_CONFIG->quality_tack; $path = $mainframe->getCfg('absolute_path') . $WBG_CONFIG->path_tack; break; } // Process the Image for Step // Check / Create Destination // Copy Image // Resize Copied if ($active) { $fullPath = $path . $newFileName; if (!is_writable($path)) { echo "<script> alert('Permission Denied for {$path}'); window.history.go(-1); </script>\n"; exit; } if (!file_exists($path . $date)) { if (!mkdir($path . $date)) { echo "<script> alert('Failed to Create Category Folder'); window.history.go(-1); </script>\n"; exit; } mosChmod($path . $date, 0777); } if (!copy($filePath, $fullPath)) { echo "<script> alert('Failed to Save Image'); window.history.go(-1); </script>\n"; exit; } if ($width && $height) { if (!$this->resize($fullPath, $fileType, $width, $height)) { echo "<script> alert('Error Resizing Image {$fileName}'); window.history.go(-1); </script>\n"; exit; } else { $imgInfo = getimagesize($fullPath); } } } } // Debug echo "Creating Database Record: " . $fileName . '<br/>'; // Store Record $row = new wbGalleryDB_img($database); $row->file = $newFileName; $row->cat_id = $defRow->cat_id; $row->name = strlen($defRow->name) ? $defRow->name : preg_replace('/\\.\\w+$/', '', $fileName); $row->description = $defRow->description; $row->photographer = $defRow->photographer; $row->price = $defRow->price; $row->sku = $defRow->sku; $row->publised = $defRow->publised; $row->created = date('Y-m-d H:i:s'); $row->modified = $row->created; $row->ordering = 0; if (is_array($origInfo)) { $row->width = $origInfo[0]; $row->height = $origInfo[1]; $row->size = $origInfo['bits']; } elseif (is_array($imgInfo)) { $row->width = $imgInfo[0]; $row->height = $imgInfo[1]; $row->size = $imgInfo['bits']; } if ($store) { // Check if (!$row->check()) { echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n"; exit; } // Store if (!$row->store()) { echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n"; exit; } // Update Ordering $row->updateOrder('cat_id = ' . (int) $row->cat_id); echo "Image Stored Successfully <br/><br/>"; return true; } else { return $row; } }
/** * @param string The name of the php (temporary) uploaded file * @param string The name of the file to put in the temp directory * @param string The message to return */ function uploadFile($filename, $userfile_name, &$msg) { josSpoofCheck(); global $mosConfig_absolute_path; $baseDir = mosPathName($mosConfig_absolute_path . '/media'); if (file_exists($baseDir)) { if (is_writable($baseDir)) { if (move_uploaded_file($filename, $baseDir . $userfile_name)) { if (mosChmod($baseDir . $userfile_name)) { return true; } else { $msg = 'Falha ao alterar as permissões do arquivo enviado.'; } } else { $msg = 'Falha ao mover o arquivo enviado para o diretório <code>/media</code>.'; } } else { $msg = 'Falha no envio pois o diretório <code>/media</code> não tem permissão. É necessário atribuir permissões de escrita.'; } } else { $msg = 'Falha no envio pois o diretório <code>/media</code> não existe.'; } return false; }
function create_dir($directory) { global $mainframe; $path = $mainframe->getCfg('absolute_path'); $dirs = split('/', $directory); foreach ($dirs as $dir) { $path .= '/' . $dir; if (!is_dir($path)) { if (!mkdir($path, 0755)) { return false; } if (!is_writable($path)) { mosChmod($path, 0755); } } } return true; }
function do_upload($file, $dest_dir) { global $clearUploads; josSpoofCheck(); if (empty($file['name'])) { mosRedirect("index2.php?option=com_media&listdir=" . $_POST['dirPath'], "Não selecionado arquivo para enviar"); } if (file_exists($dest_dir . $file['name'])) { mosRedirect("index2.php?option=com_media&listdir=" . $_POST['dirPath'], "FALHA no carregamento. O arquivo já existe"); } $format = substr($file['name'], -3); $allowable = array('bmp', 'csv', 'doc', 'epg', 'gif', 'ico', 'jpg', 'odg', 'odp', 'ods', 'odt', 'pdf', 'png', 'ppt', 'swf', 'txt', 'xcf', 'xls'); $noMatch = 0; foreach ($allowable as $ext) { if (strcasecmp($format, $ext) == 0) { $noMatch = 1; } } if (!$noMatch) { mosRedirect("index2.php?option=com_media&listdir=" . $_POST['dirPath'], 'Este tipo de arquivo não é suportado'); } if (!move_uploaded_file($file['tmp_name'], $dest_dir . strtolower($file['name']))) { mosRedirect("index2.php?option=com_media&listdir=" . $_POST['dirPath'], "Falha ao enviar arquivo"); } else { mosChmod($dest_dir . strtolower($file['name'])); mosRedirect("index2.php?option=com_media&listdir=" . $_POST['dirPath'], "Envio Completo"); } $clearUploads = true; }
function do_upload($file, $dest_dir) { global $clearUploads; josSpoofCheck(); if (empty($file['name'])) { mosRedirect("index2.php?option=com_media&listdir=" . $_POST['dirPath'], "Upload file not selected"); } if (file_exists($dest_dir . $file['name'])) { mosRedirect("index2.php?option=com_media&listdir=" . $_POST['dirPath'], "Upload FAILED. File already exists"); } $format = substr($file['name'], -3); $allowable = array('bmp', 'csv', 'doc', 'epg', 'gif', 'ico', 'jpg', 'odg', 'odp', 'ods', 'odt', 'pdf', 'png', 'ppt', 'swf', 'txt', 'xcf', 'xls'); $noMatch = 0; foreach ($allowable as $ext) { if (strcasecmp($format, $ext) == 0) { $noMatch = 1; } } if (!$noMatch) { mosRedirect("index2.php?option=com_media&listdir=" . $_POST['dirPath'], 'This file type is not supported'); } if (!move_uploaded_file($file['tmp_name'], $dest_dir . strtolower($file['name']))) { mosRedirect("index2.php?option=com_media&listdir=" . $_POST['dirPath'], "Upload FAILED"); } else { mosChmod($dest_dir . strtolower($file['name'])); mosRedirect("index2.php?option=com_media&listdir=" . $_POST['dirPath'], "Upload complete"); } $clearUploads = true; }
/** * @param string Source directory * @param string Destination directory * @param array array with filenames * @param boolean True is existing files can be replaced * @return boolean True on success, False on error */ function copyFiles($p_sourcedir, $p_destdir, $p_files, $overwrite = false) { if (is_array($p_files) && count($p_files) > 0) { foreach ($p_files as $_file) { $filesource = mosPathName(mosPathName($p_sourcedir) . $_file, false); $filedest = mosPathName(mosPathName($p_destdir) . $_file, false); if (!file_exists($filesource)) { $this->setError(1, "Arquivo {$filesource} não existe!"); return false; } else { if (file_exists($filedest) && !$overwrite) { $this->setError(1, "Já existe um arquivo chamado {$filedest} - Está a tentar instalar a mesma extensão duas vezes?"); return false; } else { $path_info = pathinfo($_file); if (!is_dir($path_info['dirname'])) { mosMakePath($p_destdir, $path_info['dirname']); } if (!(copy($filesource, $filedest) && mosChmod($filedest))) { $this->setError(1, "Falha ao copiar o arquivo: {$filesource} to {$filedest}"); return false; } } } } } else { return false; } return count($p_files); }