protected function _upload($path, $save_name, $is_replace, $is_thumb, $thumb_name, $thumb_max_width)
 {
     if (!checkDir($path)) {
         return '目录创建失败: ' . $path;
     }
     import("ORG.Net.UploadFile");
     $upload = new UploadFile();
     //设置上传文件大小
     $upload->maxSize = '2000000';
     //设置上传文件类型
     $upload->allowExts = explode(',', strtolower('jpg,gif,png,jpeg,bmp'));
     //存储规则
     $upload->saveRule = 'uniqid';
     //设置上传路径
     $upload->savePath = $path;
     //保存的名字
     $upload->saveName = $save_name;
     //是否缩略图
     $upload->thumb = $is_thumb;
     $upload->thumbMaxWidth = $thumb_max_width;
     $upload->thumbFile = $thumb_name;
     //存在是否覆盖
     $upload->uploadReplace = $is_replace;
     //执行上传操作
     if (!$upload->upload()) {
         //捕获上传异常
         return $upload->getErrorMsg();
     } else {
         //上传成功
         return $upload->getUploadFileInfo();
     }
 }
 public function up2()
 {
     $path = $_GET['folder'];
     $path2 = ROOT_PATH . "/data/test2/";
     checkDir($path2);
     $info = $this->_upload($path);
     dump($info);
 }
Example #3
0
function save()
{
    $data = json_decode(\route\getParam("data"), true);
    $parent = $data["parent"];
    $children = $data["children"];
    include PATH . "src/fileSys.php";
    checkDir();
    $attrNameArr = array('id', 'class', 'name', 'frame', 'readonly', 'type', 'placeholder');
    $styleNameArr = array('width', 'height', 'top', 'left', 'position', 'background-color', 'resize', 'right', 'bottom', 'font-size', 'color', 'z-index', 'cursor', 'border-left', 'border-right', 'border-top', 'border-bottom', 'padding-left', 'padding-right', 'padding-top', 'padding-bottom', 'margin-left', 'margin-right', 'margin-top', 'margin-bottom', 'line-height', 'text-align', 'background-image', 'background-repeat', 'border-radius', 'display', 'background-size', 'pointer-events', 'overflow', 'opacity', 'filter');
    createCss($parent, $children, $styleNameArr);
    createHtml($children, $attrNameArr);
    print '{"save": "success"}';
}
Example #4
0
    //if directory not exists, try to create it
    if (!$oDir->isDir()) {
        if (!$oDir->mkdir()) {
            printFatalError();
        }
    }
    //check if directory is writable
    if (!is_writable($oDir->path)) {
        printFatalError('[FALSE] ' . sprintf(_('%s directory %s is not writable. Please Check permissions.'), $strDirSum, $oDir->getRelativePath()));
    }
    echo "[ OK ]\n";
}
//check write permissions on PAGES PATH
checkDir('main web site pages', new PDir(PAGES_PATH));
checkDir('Cache', new PDir(CACHE_DIR));
checkDir('Medias', new PDir(MEDIAS_PATH));
echo _('Checking SITE_URL variable ....');
$strSiteUrl = str_replace(basename(__FILE__), '', $_SERVER['REQUEST_URI']);
if ($strSiteUrl != SITE_URL) {
    printFatalError(sprintf(_('
Site Url is: %s, while it should be %s.
Please change it in the web site config file: %s'), SITE_URL, $strSiteUrl, $configFile->getRelativePath()));
}
echo "[ OK ]\n";
echo _('Checking url rewriting ....');
$oFile = new PFile(SITE_PATH . '.htaccess');
if (!is_file($oFile->path)) {
    echo "[ !!!! WARNING !!!! ]\n";
    echo _('No .htaccess file has been found, you should rename the htaccess.txt file in .htaccess to active the url rewriting');
} else {
    //check the rewrite base match with the SITE_URL
/**
 * backup of flux-installation
 *
 * @param $talk : boolean if function should talk
 * @param $compression : 0 = none | 1 = gzip | 2 = bzip2
 * @return string with name of backup-archive, string with "" in error-case.
 */
function backupCreate($talk = false, $compression = 0)
{
    global $cfg, $error;
    // backup-dir
    $dirBackup = $cfg["path"] . _DIR_BACKUP;
    if (!checkDir($dirBackup)) {
        $error = "Errors when checking/creating backup-dir : " . $dirBackup;
        return "";
    }
    // files and more strings
    $backupName = "backup_" . _VERSION_THIS . "_" . date("YmdHis");
    $fileArchiveName = $backupName . ".tar";
    $tarSwitch = "-cf";
    switch ($compression) {
        case 1:
            $fileArchiveName .= ".gz";
            $tarSwitch = "-zcf";
            break;
        case 2:
            $fileArchiveName .= ".bz2";
            $tarSwitch = "-jcf";
            break;
    }
    $fileArchive = $dirBackup . '/' . $fileArchiveName;
    $fileDatabase = $dirBackup . '/database.sql';
    $fileDocroot = $dirBackup . '/docroot.tar';
    // command-strings
    $commandArchive = "cd " . $dirBackup . "; tar " . $tarSwitch . " " . $fileArchiveName . " ";
    $commandDatabase = "";
    switch ($cfg["db_type"]) {
        case "mysql":
            $commandDatabase = "mysqldump -h " . $cfg["db_host"] . " -u " . $cfg["db_user"] . " --password="******"db_pass"] . " --all -f " . $cfg["db_name"] . " > " . $fileDatabase;
            $commandArchive .= 'database.sql ';
            break;
        case "sqlite":
            $commandDatabase = "sqlite " . $cfg["db_host"] . " .dump > " . $fileDatabase;
            $commandArchive .= 'database.sql ';
            break;
    }
    $commandArchive .= 'docroot.tar';
    //$commandDocroot = "cd ".$dirBackup."; tar -cf docroot.tar ".$_SERVER['DOCUMENT_ROOT']; // with path of docroot
    $commandDocroot = "cd " . $_SERVER['DOCUMENT_ROOT'] . "; tar -cf " . $fileDocroot . " .";
    // only content of docroot
    // database-command
    if ($commandDatabase != "") {
        if ($talk) {
            sendLine('Backup of Database <em>' . $cfg["db_name"] . '</em> ...');
        }
        shell_exec($commandDatabase);
    }
    if ($talk) {
        sendLine(' <font color="green">Ok</font><br>');
    }
    // docroot-command
    if ($talk) {
        sendLine('Backup of Docroot <em>' . $_SERVER['DOCUMENT_ROOT'] . '</em> ...');
    }
    shell_exec($commandDocroot);
    if ($talk) {
        sendLine(' <font color="green">Ok</font><br>');
    }
    // create the archive
    if ($talk) {
        sendLine('Creating Archive <em>' . $fileArchiveName . '</em> ...');
    }
    shell_exec($commandArchive);
    if ($talk) {
        sendLine(' <font color="green">Ok</font><br>');
    }
    // delete temp-file(s)
    if ($talk) {
        sendLine('Deleting temp-files ...');
    }
    if ($commandDatabase != "") {
        @unlink($fileDatabase);
    }
    @unlink($fileDocroot);
    if ($talk) {
        sendLine(' <font color="green">Ok</font><br>');
    }
    // log
    if ($talk) {
        sendLine('<font color="green">Backup Complete.</font><br>');
    }
    AuditAction($cfg["constants"]["admin"], "FluxBackup Created : " . $fileArchiveName);
    return $fileArchiveName;
}
Example #6
0
function buildCache($barcode, $filename)
{
    global $basedir;
    global $resolutions;
    $filename_base = $barcode;
    // Zwischenspeicher prüfen und bei Bedarf anlegen
    $ret = checkDir($basedir . '/cache/', true, true, 0777);
    if (!$ret) {
        $errorstring = "Fehler beim Anlegen des Zwischenspeicher-Verzeichnisses! \n<br>\n";
        die($errorstring);
    } else {
        $ret = checkDir($basedir . '/cache/1600x1200/', true, true, 0777);
        if (!$ret) {
            $errorstring = "Fehler beim Anlegen des Zwischenspeicher-Verzeichnisses (1600x1200)! \n<br>\n";
            die($errorstring);
        }
        // zunächst in 1600x1200 umwandeln (als Basis für weitere Konvertierungen)
        $baseimage_filename = $basedir . '/cache/1600x1200/' . $filename_base . '.jpg';
        $res = '1600x1200';
        $ret = convertImage($filename, $baseimage_filename, $res, false);
        if (!$ret) {
            $errorstring = "Fehler beim Umrechnen des Bildes in die Aufl&ouml;sung 1600x1200! \n<br>\n";
            die($errorstring);
        }
        foreach ($resolutions as $res) {
            // Unterverzeichnisse für einzelne Auflösungen prüfen
            $ret = checkDir($basedir . '/cache/' . $res, true, true, 0777);
            if (!$ret) {
                $errorstring = "Fehler beim Anlegen des Zwischenspeicher-Verzeichnisses (" . $res . ")\n<br>\n";
                die($errorstring);
            }
            if ($res == '120x90') {
                $is_thumbnail = true;
            } else {
                $is_thumbnail = false;
            }
            $output_filename = $basedir . '/cache/' . $res . '/' . $filename_base . '.jpg';
            $ret = convertImage($baseimage_filename, $output_filename, $res, $is_thumbnail);
            if (!$ret) {
                $errorstring = "Fehler beim Umrechnen des Bildes in die Aufl&ouml;sung (" . $res . ")! \n<br>\n";
                die($errorstring);
            }
        }
    }
}
Example #7
0
 protected function _upload($path)
 {
     if (!checkDir($path)) {
         return '目录创建失败: ' . $path;
     }
     import("ORG.Net.UploadFile");
     $upload = new UploadFile();
     //设置上传文件大小
     $upload->maxSize = '2000000';
     //设置上传文件类型
     $upload->allowExts = explode(',', strtolower('jpg,gif,png,jpeg'));
     //存储规则
     $upload->saveRule = 'uniqid';
     //设置上传路径
     $upload->savePath = $path;
     //执行上传操作
     if (!$upload->upload()) {
         //捕获上传异常
         return $upload->getErrorMsg();
     } else {
         //上传成功
         return $upload->getUploadFileInfo();
     }
 }
Example #8
0
}
//解析参数
$w = $_GET['w'] ? $_GET['w'] : '100';
//宽度
$h = $_GET['h'] ? $_GET['h'] : '100';
//高度
$t = $_GET['t'] ? $_GET['t'] : 'c';
//是否切割
$r = $_GET['r'] ? '1' : '0';
//是否覆盖
//目录名hash
$fileHash = md5($url . $w . $h);
$hashPath = substr($fileHash, 0, 2) . '/' . substr($fileHash, 2, 2) . '/';
//缩图目录
$thumbDir = "./data/thumb/" . $hashPath;
checkDir($thumbDir);
$tempFile = $tempDir . $fileHash . '.' . $sourceInfo['type'];
$thumbFile = $thumbDir . $fileHash . "_" . $w . "_" . $h . "_" . $t . '.' . $sourceInfo['type'];
$img = new Image();
//判断是否替换,存在则跳转,不存在继续进行
if (!$r && file_exists($thumbFile)) {
    //这里有2种方法,第一种多一次跳转,多一个http连接数,第二种,要进行一次php处理,多占用一部分内存。
    //header('location:'.$thumbFile);
    $img->showImg($thumbFile);
}
//不存在输出
if (copy($url, $tempFile)) {
    //判断图片大小 如果图片宽和高都小于要缩放的比例 直接输出
    $info = getimagesize($tempFile);
    //判断处理图片大约需要的内存
    $need_memory = $info[0] * $info[1] / 100000;
Example #9
0
    }
} else {
    $picname = $_FILES['mypic']['name'];
    $picsize = $_FILES['mypic']['size'];
    if ($picname != "") {
        if ($picsize > 1024000) {
            //echo '图片大小不能超过1M';
            $arr = array('name' => '图片大小不能超过1M', 'pic' => '', 'size' => '', 'error' => '1');
            echo json_encode($arr);
            exit;
        }
        $type = strstr($picname, '.');
        if ($type != ".gif" && $type != ".jpg" && $type != ".png") {
            //echo '图片格式不对!';
            $arr = array('name' => '图片格式不对', 'pic' => '', 'size' => '', 'error' => '1');
            echo json_encode($arr);
            exit;
        }
        $rand = rand(100, 999);
        $pics = date("YmdHis") . $rand . $type;
        //上传路径
        $pic_path = SYS_PATH . 'photos/files/' . date('Ym') . '/' . date('d') . '/' . $pics;
        checkDir($pic_path);
        if (move_uploaded_file($_FILES['mypic']['tmp_name'], $pic_path)) {
            //生成缩略图
        }
    }
    $size = round($picsize / 1024, 2);
    $arr = array('name' => $picname, 'pic' => 'photos/files/' . date('Ym') . '/' . date('d') . '/' . $pics, 'size' => $size, 'error' => '0');
    echo json_encode($arr);
}
Example #10
0
    function check_theme()
    {
        global $upload_dir, $settingsimages, $settingsimagesUrl, $galleryimages, $timthumbCacheDir;
        $re = '<table cellpadding="0" style="width:590px; margin:20px;" class="widefat">
				<thead>
					<tr>
						<th colspan="2">THEME CHECK RESULTS</th>
					</tr>
					<tr>
						<th width="50">STATUS</th>
						<th>ITEM</th>
					</tr>
				</thead>                
				<tbody>';
        $re .= addCheckItem(array('name' => 'TimThumb PHP Script', 'status' => 'wait', 'id' => 'timthumbcheck', 'ErrMessage' => 'ThimThumb image resizer script is not working on your server!', 'ErrInfo' => 'This script resizes and crop the images. Without this script, you must edit your images manually.'));
        $chErr = checkDir($upload_dir['basedir'], 0777);
        $re .= addCheckItem(array('name' => 'Upload Directory', 'status' => $chErr['status'], 'ErrMessage' => $chErr['err'], 'ErrInfo' => 'This directory usually being used by WordPress for all media files. <strong>Default is wp-content/uploads</strong>. For that reason, you can\'t upload any image files without createing and giving its permissions.'));
        $chErr = checkDir($settingsimages, 0777);
        $re .= addCheckItem(array('name' => 'Image Manager Directory', 'status' => $chErr['status'], 'ErrMessage' => $chErr['err'], 'ErrInfo' => 'This folder is used by Image Manager in General Theme Settings. In order to run this function, this folder must be created.'));
        $chErr = checkDir($galleryimages, 0777);
        $re .= addCheckItem(array('name' => 'Gallery Images Directory', 'status' => $chErr['status'], 'ErrMessage' => $chErr['err'], 'ErrInfo' => 'This folder is used for uploading images in Gallery section.'));
        $chErr = checkDir($timthumbCacheDir, 0777);
        $re .= addCheckItem(array('name' => 'TimThumb Cache Directory', 'status' => $chErr['status'], 'ErrMessage' => $chErr['err'], 'ErrInfo' => 'If ThimThumb will be used, this folder must have needed permission.'));
        $wpnavi = function_exists('wp_pagenavi') ? 'ok' : 'nok';
        $re .= addCheckItem(array('name' => 'WP-PageNavi Plugin', 'status' => $wpnavi, 'ErrMessage' => 'Please Install and Activate WP-PageNavi Plugin.', 'ErrInfo' => 'This plugin is used for pagination in Blog and Portfolio sections. You can find this plugin in downloaded files / plugins folder.(You can watch the video about plugin installation)'));
        $getContentRemote = @file_get_contents('http://www.renklibeyaz.com/rightnow.xml');
        $getContentRemoteStatus = empty($getContentRemote) ? 'nok' : 'ok';
        $re .= addCheckItem(array('name' => 'file_get_contents Remote Server Access', 'status' => $getContentRemoteStatus, 'ErrMessage' => 'Your server is blocking "Remote Server Connection". Please contact your host provider to allow "file_get_contents" php function.', 'ErrInfo' => 'This function gets the thumbnail of the video files, update the fonts and displaying notice about theme updates.'));
        $sxml = function_exists('simplexml_load_string') ? 'ok' : 'nok';
        $re .= addCheckItem(array('name' => 'PHP SimpleXml Class', 'status' => $sxml, 'ErrMessage' => 'Your server doesn\'t have "SimpleXml Class" which is a PHP Class.', 'ErrInfo' => 'This Class gets the thumbnail of the video files, displaying notice about theme updates.'));
        $curlStatus = function_exists('curl_init') ? 'ok' : 'nok';
        $re .= addCheckItem(array('name' => 'PHP cURL Class', 'status' => $curlStatus, 'ErrMessage' => 'Your server doesn\'t have "cURL Class" which is a PHP Class.', 'ErrInfo' => 'This Class is displaying notice about theme updates.'));
        $re .= '</tbody>
		<table>';
        echo $re;
        die;
    }
 function _uploadfile($inputname, $attachdir)
 {
     if (!checkDir($attachdir . "/")) {
         return '目录创建失败: ' . $attachdir;
     }
     $dirtype = 1;
     //1:按天存入目录 2:按月存入目录 3:按扩展名存目录  建议使用按天存
     $maxattachsize = 2097152;
     //最大上传大小,默认是2M
     $err = "";
     $msg = "";
     $upfile = $_FILES[$inputname];
     if (!empty($upfile['error'])) {
         switch ($upfile['error']) {
             case '1':
                 $err = '文件大小超过了php.ini定义的upload_max_filesize值';
                 break;
             case '2':
                 $err = '文件大小超过了HTML定义的MAX_FILE_SIZE值';
                 break;
             case '3':
                 $err = '文件上传不完全';
                 break;
             case '4':
                 $err = '无文件上传';
                 break;
             case '6':
                 $err = '缺少临时文件夹';
                 break;
             case '7':
                 $err = '写文件失败';
                 break;
             case '8':
                 $err = '上传被其它扩展中断';
                 break;
             case '999':
             default:
                 $err = '无有效错误代码';
         }
     } elseif (empty($upfile['tmp_name']) || $upfile['tmp_name'] == 'none') {
         $err = '无文件上传';
     } else {
         $temppath = $upfile['tmp_name'];
         $attachinfo = @getimagesize($temppath);
         if ($attachinfo[2] == IMAGETYPE_GIF || $attachinfo[2] == IMAGETYPE_JPEG || $attachinfo[2] == IMAGETYPE_PNG) {
             $extension = image_type_to_extension($attachinfo[2], false);
             $filesize = filesize($temppath);
             if ($filesize <= $maxattachsize) {
                 switch ($dirtype) {
                     case 1:
                         $attach_subdir = 'day_' . date('ymd');
                         break;
                     case 2:
                         $attach_subdir = 'month_' . date('ym');
                         break;
                     case 3:
                         $attach_subdir = 'ext_' . $extension;
                         break;
                 }
                 $attach_dir = $attachdir . '/' . $attach_subdir;
                 if (!is_dir($attach_dir)) {
                     @mkdir($attach_dir, 0777);
                     @fclose(fopen($attach_dir . '/index.htm', 'w'));
                 }
                 PHP_VERSION < '4.2.0' && mt_srand((double) microtime() * 1000000);
                 $filename = date("YmdHis") . mt_rand(1000, 9999) . '.' . $extension;
                 $target2 = $attach_dir . '/' . $filename;
                 $attachdir = ltrim($attachdir, ".");
                 $target = C("TS_URL") . $attachdir . "/" . $attach_subdir . "/" . $filename;
                 move_uploaded_file($upfile['tmp_name'], $target2);
                 $msg = $target;
             } else {
                 $err = '文件大小超过' . $maxattachsize . '字节';
             }
         } else {
             $err = '文件格式必需为以下格式:jpg,gif,png';
         }
         @unlink($temppath);
     }
     return array('err' => $err, 'msg' => $msg);
 }
 public function upload($attach_type = 'attach_type', $path, $save_name, $options = array())
 {
     //检查文件名和目录是否为空
     if (empty($path)) {
         $path = C('UPLOAD_PATH') . '/' . date('Ymd') . '/';
     }
     //创建目录
     if (!checkDir($path)) {
         $return['status'] = false;
         $return['info'] = '目录创建失败: ' . $path;
         return $return;
     }
     import("ORG.Net.UploadFile");
     $upload = new UploadFile();
     //设置上传文件大小
     $upload->maxSize = empty($options['maxsize']) ? '2000000' : $options['maxsize'];
     //设置上传文件类型
     $upload->allowExts = empty($options['allowExts']) ? explode(',', strtolower('jpg,gif,png,jpeg,bmp')) : explode(',', $options['allowExts']);
     //存储规则
     $upload->saveRule = 'uniqid';
     //设置上传路径
     $upload->savePath = $path;
     //保存的名字
     $upload->saveName = $save_name;
     //是否缩略图
     $upload->thumb = empty($options['is_thumb']) ? false : $options['is_thumb'];
     $upload->thumbMaxWidth = empty($options['thumb_width']) ? '200' : $options['thumb_width'];
     $upload->thumbFile = empty($options['thumb_file']) ? 'thumb_' . $save_name : $options['thumb_file'];
     //存在是否覆盖
     $upload->uploadReplace = empty($options['is_replace']) ? true : $options['is_replace'];
     //执行上传操作
     if (!$upload->upload()) {
         //上传失败,返回错误
         $return['status'] = false;
         $return['info'] = $upload->getErrorMsg();
         return $return;
     } else {
         $upload_info = $upload->getUploadFileInfo();
         //保存信息到附件表
         $api = new TS_API();
         $uid = $api->user_getLoggedInUser();
         foreach ($upload_info as $u) {
             unset($map);
             $map['attach_type'] = $attach_type;
             $map['userId'] = $uid;
             $map['uploadTime'] = time();
             $map['name'] = $u['name'];
             $map['type'] = $u['type'];
             $map['size'] = $u['size'];
             $map['extension'] = $u['extension'];
             $map['hash'] = $u['hash'];
             $map['savepath'] = $u['savepath'];
             $map['savename'] = $u['savename'];
             //$map['savedomain']=	C('ATTACH_SAVE_DOMAIN');
             $result = $this->add($map);
             $map['id'] = $result;
             $infos[] = $map;
         }
         //输出信息
         $return['status'] = true;
         $return['info'] = $infos;
         //上传成功,返回信息
         return $return;
     }
 }
 function doChangeFace()
 {
     $userId = $this->mid;
     $path = './Public/Uploads/User/' . $userId . '/images/';
     checkDir($path);
     $info = $this->_upload($path);
     if ($info) {
         $file = $info[0]['savepath'] . $info[0]['savename'];
         include "./Include/Image.class.php";
         //生成头像缩略图
         $img = new Image();
         //小图
         $w = 48;
         $h = 48;
         $face = './Public/Uploads/User/' . $userId . '/face_s.jpg';
         $img->cutThumb($file, $face, $w, $h);
         //中图
         $w = 96;
         $h = 96;
         $face = './Public/Uploads/User/' . $userId . '/face_m.jpg';
         $img->cutThumb($file, $face, $w, $h);
         //大图
         $w = 200;
         $h = 400;
         $face = './Public/Uploads/User/' . $userId . '/face_b.jpg';
         $img->thumb($file, '', $face, $w, $h);
         //原图大小
         $face = './Public/Uploads/User/' . $userId . '/face_o.jpg';
         copy($file, $face);
         //保存头像附件
         $dao = D('Attach');
         $dao->create($info[0]);
         $dao->module = 'Face';
         $dao->recordId = $this->mid;
         $dao->userId = $this->mid;
         $dao->uploadTime = time();
         $dao->add();
         /* add_user_feed */
         $feedTitle = "上传了新头像";
         $this->addUserFeed($userId, 'add', 'face', $userId, $feedTitle);
         /* /add_user_feed */
     }
     //header("location:".__URL__."/face?up=ok");
     $this->redirect('face');
 }
Example #14
0
function getUploadsPath($module = 'attach')
{
    //每100个相册放到一个文件夹
    $upload_path = C('UPLOAD_PATH') . $module . '/' . date('Y', time()) . '/' . date('m-d', time()) . '/';
    checkDir($upload_path);
    return $upload_path;
}
Example #15
0
function CropSquare($img, $s, $newfilename)
{
    if (file_exists($newfilename)) {
        return $newfilename;
    }
    checkDir($newfilename);
    $strY = 0;
    $strX = 0;
    //Check if GD extension is loaded
    if (!extension_loaded('gd') && !extension_loaded('gd2')) {
        trigger_error("GD is not loaded", E_USER_WARNING);
        return false;
    }
    //Get Image size info
    $imgInfo = getimagesize($img);
    $nHeight = $imgInfo[1];
    $nWidth = $imgInfo[0];
    switch ($imgInfo[2]) {
        case 1:
            $im = imagecreatefromgif($img);
            break;
        case 2:
            $im = imagecreatefromjpeg($img);
            break;
        case 3:
            $im = imagecreatefrompng($img);
            break;
        default:
            trigger_error('Unsupported filetype!', E_USER_WARNING);
            break;
    }
    //If image dimension is smaller, do not resize
    if ($imgInfo[0] <= $s && $imgInfo[1] <= $s) {
        $nHeight = $imgInfo[1];
        $nWidth = $imgInfo[0];
        return $img;
    } else {
        //yeah, resize it, but keep it proportional
        if ($nHeight > $nWidth) {
            $ww = $s;
            $hh = $nHeight * $s / $nWidth;
            $strY = ($nHeight - $nWidth) / 2;
            $side = $imgInfo[0];
        } else {
            $hh = $s;
            $ww = $nWidth * $s / $nHeight;
            $strX = ($nWidth - $nHeight) / 2;
            $side = $imgInfo[1];
        }
    }
    $newImg = imagecreatetruecolor($s, $s);
    /* Check if this image is PNG or GIF, then set if Transparent */
    if ($imgInfo[2] == 1 or $imgInfo[2] == 3) {
        imagealphablending($newImg, false);
        imagesavealpha($newImg, true);
        $transparent = imagecolorallocatealpha($newImg, 255, 255, 255, 127);
        imagefilledrectangle($newImg, 0, 0, $s, $s, $transparent);
    }
    imagecopyresampled($newImg, $im, 0, 0, $strX, $strY, $s, $s, $side, $side);
    //Generate the file, and rename it to $newfilename
    switch ($imgInfo[2]) {
        case 1:
            imagegif($newImg, $newfilename);
            break;
        case 2:
            imagejpeg($newImg, $newfilename, 100);
            break;
        case 3:
            imagepng($newImg, $newfilename);
            break;
        default:
            trigger_error('Failed resize image!', E_USER_WARNING);
            break;
    }
    return $newfilename;
}
<?php

//ALTERANDO DOCUMENTO PARA HTML
header('Content-Type: text/html; charset=utf-8');
function checkDir($Dir)
{
    if (file_exists($Dir) && is_dir($Dir)) {
        return true;
    } else {
        return false;
    }
}
$getDir = getcwd();
$setDir = "{$getDir}/04";
echo "{$getDir}<hr>";
if (!checkDir($setDir)) {
    mkdir($setDir, 0777);
}
//if(checkDir($setDir)):
//    rmdir($setDir);
//endif;
//rename($setDir, "{$getDir}/uploads");
//rename("{$getDir}/05", "{$setDir}/05");
chdir($setDir);
echo getcwd();
echo "<hr>";
$newDir = getcwd();
$openDir = opendir($newDir);
while ($File = readdir($openDir)) {
    if ($File != '.' && $File != '..') {
        echo "<img src='04/{$File}' width='150'/><br>";
Example #17
0
function downloadPackages($packageList, $packageURL, $packageDir, $packageRepository)
{
    global $cli;
    showMessage2("Configuring...");
    if (!is_array($packageList) || count($packageList) == 0) {
        showError("Package list is empty. Aborting...");
    }
    // 1. check if packages specified in $packageList exist in $packageRepository(means already downloaded and imported).
    //    if yes - ask user to do download or not. If not - go out
    foreach (array_keys($packageList) as $k) {
        $packageName = $packageList[$k];
        $package = eZPackage::fetch($packageName);
        if (is_object($package)) {
            global $autoMode;
            if ($autoMode == 'on') {
                $action = 'y';
            } else {
                $action = getUserInput("Package '{$packageName}' already imported. Import it anyway? [y/n]: ");
            }
            if (strpos($action, 'n') === 0) {
                unset($packageList[$k]);
            } else {
                eZDir::recursiveDelete(eZPackage::repositoryPath() . "/{$packageRepository}/{$packageName}");
            }
        }
    }
    if (count($packageList) == 0) {
        // all packages are imported.
        return true;
    }
    // 2. check $packgesList exists in $packageDir(means packages downloaded but not imported)
    //    if yes - ask user to import or not. If not - go out
    if (!checkDir($packageDir)) {
        return false;
    }
    $downloadPackageList = array();
    foreach ($packageList as $packageName) {
        if (file_exists("{$packageDir}/{$packageName}.ezpkg")) {
            global $autoMode;
            if ($autoMode == 'on') {
                $action = 'y';
            } else {
                $action = getUserInput("Package '{$packageName}' already downloaded. Download it anyway? [y/n]: ");
            }
            if (strpos($action, 'n') === 0) {
                continue;
            }
        }
        $downloadPackageList[] = $packageName;
    }
    //
    // download
    //
    showMessage2("Downloading...");
    if (count($downloadPackageList) > 0) {
        // TODO: using 'eZStepSiteTypes' is hack.
        //       need to exclude 'downloadFile' from that class.
        $tpl = false;
        $http = false;
        $ini = false;
        $persistenceList = false;
        $downloader = new eZStepSiteTypes($tpl, $http, $ini, $persistenceList);
        foreach ($downloadPackageList as $packageName) {
            showMessage("{$packageName}");
            $archiveName = $downloader->downloadFile("{$packageURL}/{$packageName}.ezpkg", $packageDir);
            if ($archiveName === false) {
                showError("download error - " . $downloader->ErrorMsg);
            }
        }
    }
    //
    // import
    //
    showMessage2("Importing...");
    foreach ($packageList as $packageName) {
        showMessage("{$packageName}");
        $package = eZPackage::import("{$packageDir}/{$packageName}.ezpkg", $packageName, false, $packageRepository);
        if (!is_object($package)) {
            showError("Faild to import '{$packageName}' package: err = {$package}");
        }
    }
    return true;
}
Example #18
0
function UF($userId, $name, $value = '')
{
    $path = C("USER_DATA_PATH") . $userId . "/";
    if ($value == 'clean') {
        unlink($path . $name . ".php");
    } else {
        checkDir($path);
        return F($name, $value, '-1', $path);
    }
}