Jump to content

gdfhghjdfghgfhf

Members
  • Posts

    218
  • Joined

  • Last visited

Posts posted by gdfhghjdfghgfhf

  1. I paid a programmer to make a shop basket script to work with Spreadshirt API. Everything is working perfectly, except that the basket keeps empting itself. I think the session is lost at some point so the script creates another BasketId.

    I tried to find if there was a specific reason it was happenning, without any success... I can't reproduce the bug. It just happens randomly without any reason. Closing the browser, resetting apache or even the whole webserver won't provoke session lost.

    I've got two different scripts working with cookies on the same domain and they don't have any problem (one is a cookie for the admin login session and the other cookie is to save the user's last viewed articles on the shop)

    I tried all solutions found on google without any success : editing php.ini , forcing ini settings through php, tried the htaccess way, ...

    Here's the "sessions" part of my phpinfo: http://gyazo.com/168e2144ddd9ee368a05754dfd463021

    shop-ajax.php (session handling @ line 18)
     

        ini_set('session.cookie_domain', '.mywebsite.com' );
        header("Pragma: no-cache");
        header("Cache-Control: no-store, no-cache, max-age=0, must-revalidate");
        $language = addslashes($_GET['l']);
        $shopid = addslashes($_GET['shop']);
        
        
        // if($_SERVER['HTTP_X_REQUESTED_WITH'] != 'XMLHttpRequest') {
        //     die("no direct access allowed");
        // }
        
        
        
        if(!session_id()) {
          $lifetime=60 * 60 * 24 * 365;
          $domain = ".mywebsite.com";
           session_set_cookie_params($lifetime,"/",$domain);
            @session_start();
        }
        
        
        
        
        
        // Configuration
        $config['ShopSource'] = "com";
        $config['ShopId'] = $shopid;
        $config['ShopKey'] = "*****";
        $config['ShopSecret'] = "*****";
        
        
        
        /*
         * add an article to the basket
        */
        if (isset($_POST['size']) && isset($_POST['appearance']) && isset($_POST['quantity'])) {
            /*
             * create an new basket if not exist
            */
            if (!isset($_SESSION['basketUrl'])) {
                /*
                 * get shop xml
                */
                $stringApiUrl = 'http://api.spreadshirt.'.$config['ShopSource'].'/api/v1/shops/' . $config['ShopId'];
                $stringXmlShop = oldHttpRequest($stringApiUrl, null, 'GET');
                if ($stringXmlShop[0]!='<') die($stringXmlShop);
                $objShop = new SimpleXmlElement($stringXmlShop);
                if (!is_object($objShop)) die('Basket not loaded');
        
                /*
                 * create the basket
                */
                $namespaces = $objShop->getNamespaces(true);
                $basketUrl = createBasket('net', $objShop, $namespaces);
                $_SESSION['basketUrl'] = $basketUrl;
                $_SESSION['namespaces'] = $namespaces;
        
                /*
                 * get the checkout url
                */
                $checkoutUrl = checkout($_SESSION['basketUrl'], $_SESSION['namespaces']);
        
                // basket language workaround
                if ($language=="fr") {
                    if (!strstr($checkoutUrl,'/fr')) {
                        $checkoutUrl = str_replace("spreadshirt.com","spreadshirt.com/fr",$checkoutUrl);
                    }
                }
        
                $_SESSION['checkoutUrl'] = $checkoutUrl;
        
            }
        
        
        
            /*
            Workaround for not having the appearance id 
            */
            if ($_POST['appearance']==0) {
                $stringApiArticleUrl = 'http://api.spreadshirt.'.$config['ShopSource'].'/api/v1/shops/' . $config['ShopId'].'/articles/'.intval($_POST['article']).'?fullData=true';
                $stringXmlArticle = oldHttpRequest($stringApiArticleUrl, null, 'GET');
                if ($stringXmlArticle[0]!='<') die($stringXmlArticle);
                $objArticleShop = new SimpleXmlElement($stringXmlArticle);
                if (!is_object($objArticleShop)) die('Article not loaded');
                $_POST['appearance'] = intval($objArticleShop->product->appearance['id']);
            }
        
        
            /*
             * article data to be sent to the basket resource
            */
            $data = array(
        
                    'articleId' => intval($_POST['article']),
                    'size' => intval($_POST['size']),
                    'appearance' => intval($_POST['appearance']),
                    'quantity' => intval($_POST['quantity']),
                    'shopId' => $config['ShopId']
        
            );
        
            /*
             * add to basket
            */
            addBasketItem($_SESSION['basketUrl'] , $_SESSION['namespaces'] , $data);
        
            $basketData = prepareBasket();
        
        
            echo json_encode(array("c" => array("u" => $_SESSION['checkoutUrl'],"q" => $basketData[0],"l" => $basketData[1])));
        }
        
        
        
        
        // no call, just read basket if not empty
        if (isset($_GET['basket'])) {
            if (array_key_exists('basketUrl',$_SESSION) && !empty($_SESSION['basketUrl'])) {
        
                $basketData = prepareBasket();
        
                echo json_encode(array("c" => array("u" => $_SESSION['checkoutUrl'],"q" => $basketData[0],"l" => $basketData[1])));
            } else {
                echo json_encode(array("c" => array("u" => "","q" => 0,"l" => "")));
            }
        }
        
        
        
        
        
        
        function prepareBasket() {
        
            $intInBasket=0;
        
            if (isset($_SESSION['basketUrl'])) {
                $basketItems=getBasket($_SESSION['basketUrl']);
        
                if(!empty($basketItems)) {
                    foreach($basketItems->basketItems->basketItem as $item) {
                        $intInBasket += $item->quantity;
                    }
                }
            }
        
            $l = "";
            $pQ = parse_url($_SESSION['checkoutUrl']);
            if (preg_match("#^basketId\=([0-9a-f\-])*$#i", $pQ['query'])) {
                $l = $pQ['query'];
            }
        
            return array($intInBasket,$l);
        }
        
        
        
        
        
        
        
        // Additional functions
        function addBasketItem($basketUrl, $namespaces, $data) {
            global $config;
        
            $basketItemsUrl = $basketUrl . "/items";
        
            $basketItem = new SimpleXmlElement('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
                    <basketItem xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://api.spreadshirt.net">
                    <quantity>' . $data['quantity'] . '</quantity>
                    <element id="' . $data['articleId'] . '" type="sprd:article" xlink:href="http://api.spreadshirt.'.$config['ShopSource'].'/api/v1/shops/' . $data['shopId'] . '/articles/' . $data['articleId'] . '">
                    <properties>
                    <property key="appearance">' . $data['appearance'] . '</property>
                    <property key="size">' . $data['size'] . '</property>
                    </properties>
                    </element>
                    <links>
                    <link type="edit" xlink:href="http://' . $data['shopId'] .'.spreadshirt.' .$config['ShopSource'].'/-A' . $data['articleId'] . '"/>
                    <link type="continueShopping" xlink:href="http://' . $data['shopId'].'.spreadshirt.'.$config['ShopSource'].'"/>
                    </links>
                    </basketItem>');
        
            $header = array();
            $header[] = createAuthHeader("POST", $basketItemsUrl);
            $header[] = "Content-Type: application/xml";
            $result = oldHttpRequest($basketItemsUrl, $header, 'POST', $basketItem->asXML());
        }
        
        
        
        function createBasket($platform, $shop, $namespaces) {
        
            $basket = new SimpleXmlElement('<basket xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://api.spreadshirt.net">
                    <shop id="' . $shop['id'] . '"/>
                    </basket>');
        
            $attributes = $shop->baskets->attributes($namespaces['xlink']);
            $basketsUrl = $attributes->href;
            $header = array();
            $header[] = createAuthHeader("POST", $basketsUrl);
            $header[] = "Content-Type: application/xml";
            $result = oldHttpRequest($basketsUrl, $header, 'POST', $basket->asXML());
            $basketUrl = parseHttpHeaders($result, "Location");
        
            return $basketUrl;
        
        }
        
        
        
        
        
        
        function checkout($basketUrl, $namespaces) {
        
            $basketCheckoutUrl = $basketUrl . "/checkout";
            $header = array();
            $header[] = createAuthHeader("GET", $basketCheckoutUrl);
            $header[] = "Content-Type: application/xml";
            $result = oldHttpRequest($basketCheckoutUrl, $header, 'GET');
            $checkoutRef = new SimpleXMLElement($result);
            $refAttributes = $checkoutRef->attributes($namespaces['xlink']);
            $checkoutUrl = (string)$refAttributes->href;
        
            return $checkoutUrl;
        
        }
        
        /*
         * functions to build headers
        */
        function createAuthHeader($method, $url) {
            global $config;
        
            $time = time() *1000;
            $data = "$method $url $time";
            $sig = sha1("$data ".$config['ShopSecret']);
        
            return "Authorization: SprdAuth apiKey=\"".$config['ShopKey']."\", data=\"$data\", sig=\"$sig\"";
        
        }
        
        
        function parseHttpHeaders($header, $headername) {
        
            $retVal = array();
            $fields = explode("\r\n", preg_replace('/\x0D\x0A[\x09\x20]+/', ' ', $header));
        
            foreach($fields as $field) {
        
                if (preg_match('/(' . $headername . '): (.+)/m', $field, $match)) {
                    return $match[2];
                }
        
            }
        
            return $retVal;
        
        }
        
        function getBasket($basketUrl) {
        
            $header = array();
            $basket = "";
        
            if (!empty($basketUrl)) {
                $header[] = createAuthHeader("GET", $basketUrl);
                $header[] = "Content-Type: application/xml";
                $result = oldHttpRequest($basketUrl, $header, 'GET');
                $basket = new SimpleXMLElement($result);
            }
        
            return $basket;
        
        }
        
        
        
        
        function oldHttpRequest($url, $header = null, $method = 'GET', $data = null, $len = null) {
        
            switch ($method) {
        
                case 'GET':
        
                    $ch = curl_init($url);
                    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
                    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                    curl_setopt($ch, CURLOPT_HEADER, false);
        
                    if (!is_null($header)) curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
        
                    break;
        
                case 'POST':
        
                    $ch = curl_init($url);
                    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
                    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                    curl_setopt($ch, CURLOPT_HEADER, true);
                    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
                    curl_setopt($ch, CURLOPT_POST, true); //not createBasket but addBasketItem
                    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        
                    break;
        
            }
        
            $result = curl_exec($ch);
            curl_close($ch);
        
            return $result;
        
        }
        ?>


    There's also 2 other parts of the script : a form to add a sample tshirt to the basket (example.php) and a script to call the ajax (shop-controller.js). Can post it if needed but there's no session handling stuff.

  2. I have a script that will output the filenames of all files inside a zip. Problem is that the accents characters are not displayed (é è â ô, etc)
     

            margin: 0px;
            padding: 6px;
            border: 1px inset;
            width: 750px;
            height: 274px;
            text-align: left;
            overflow: auto">header('Content-Type: text/html; charset=utf-8');
    setlocale(LC_ALL, 'fr_CA.UTF-8');
    ini_set('display_startup_errors', 1);
    error_reporting(E_ALL);
    ini_set('display_errors', 1);
                $downloadlink = "test.zip";
                $za = new ZipArchive();
                $za->open($downloadlink);
                    $open = $za->open($downloadlink, ZIPARCHIVE::CHECKCONS);
                for( $i = 0; $i < $za->numFiles; $i++ ){
                    $stat = $za->statIndex( $i );
                    $tounes = array( basename( $stat['name'] ) . PHP_EOL );
                    foreach($tounes as $toune) {
    echo "$toune<br>";
                    }
        }

    You can download the file i am testing with (test.zip) here:
    pirate-punk.com/test.zip

    I need a fix that will display any filename with any accent.

    I've been desesperatly looking for help on multiple forums and nobody never came up with a solution. So just tell me your price (make it reasonnable please) and i will paypal it to you once you can confirm a solution has been found.

     

     

    Notes:

     

    - The encoding header of the php file needs to stay utf8 as the rest of the page will need to be utf8

    - i can't predict what will be the encoding of the zip file since the zips are user-uploaded so the encoding depends on their system.

  3. I have a script that will search for a file inside all directories of my server, then return the full path to the file. The search query comes encoded in base64.

    The script works perfectly when searching a file without accents. But as soon as i search for something with accents, it won't work.

    Here is my file structure:

     

     

    /var/www/clients/client2/web1/web/dl/pp/6250/Ya Basta! - 2002 - Lucha Y Fiesta.zip

    /var/www/clients/client2/web1/web/dl/pp/6250/La Souris Déglinguée - 1988 - Quartier Libre.zip

     

    When searching for the first file (WWEgQmFzdGEhIC0gMjAwMiAtIEx1Y2hhIFkgRmllc3RhLnppcA==) it will return the correct path. But when searching for the second file with accents (TGEgU291cmlzIETpZ2xpbmd16WUgLSAxOTg4IC0gUXVhcnRpZXIgTGlicmUuemlw) it will not return any result even if the file exists

    Here's the script:

    header("Content-type: text/html; charset=utf-8");
    
    // $encodedquery = "WWEgQmFzdGEhIC0gMjAwMiAtIEx1Y2hhIFkgRmllc3RhLnppcA==";  // query without accent = WORKS !
    $encodedquery = "TGEgU291cmlzIETpZ2xpbmd16WUgLSAxOTg4IC0gUXVhcnRpZXIgTGlicmUuemlw" // query with accents = DOESNT WORKS
    
    $decode = utf8_encode(base64_decode($encodedquery);
    $search = preg_quote($decode);
    echo "searching for \"$search\" ....";
    
            function rsearch($folder, $pattern) {
                $dir = new RecursiveDirectoryIterator($folder);
                $ite = new RecursiveIteratorIterator($dir);
                $files = new RegexIterator($ite, $pattern, RegexIterator::GET_MATCH);
                $fileList = array();
                foreach($files as $file) {
                    $fileList = array_merge($fileList, $file);
                }
                return $fileList;
            }
    
            $root = $_SERVER['DOCUMENT_ROOT'];
            $resultatss = rsearch($root, '/.*\/'.$search.'/');
    
    foreach ($resultatss as $resultat) {
    echo "<br>FOUND FILE = $resultat";
    }
    
  4. Thanks for the reply.

     

    2 problems now :

     

    - The image is saved as PNG in the cache folder, but isn't resized.

    - The first time i will load the image, i will get an error (image cannot be displayed because it contains error) but the image will still be saved as PNG in the cache folder. Second time i load the image, it will be displayed correctly (using the cached version) but it isn't resized.

     

    Here's the full code of my page. The first part is used to cache the image, the second part is used to display the non-cached image (it reads an image from a ZIP file and output the content without extracting anything)

     

     

    pochette.php :

    if (empty($_GET['display'])) {
    header('Content-Type: image/png');
    
    			$imgpochette = $_GET['i'];
    
    			$ENABLE_CACHE = true;
    			$CACHE_TIME_HOURS = 744;
    			$CACHE_FILE_PATH = "pochette_album/$imgpochette.png";
    
    			if($ENABLE_CACHE && file_exists($CACHE_FILE_PATH) && (time() - filemtime($CACHE_FILE_PATH) < ($CACHE_TIME_HOURS * 60 * 60))) {
    			  echo @file_get_contents($CACHE_FILE_PATH);
    			} else {
    					// Load the requested image
    					$imgdisplay = "http://www.pirate-punk.com/pochette.php?i=$imgpochette&display=1";
    					$image = imagecreatefromstring(file_get_contents($imgdisplay));
    $width = "30";
    $height = "30";
    list($originalWidth, $originalHeight) = getimagesize($CACHE_FILE_PATH);
    $new_image = imagecreatetruecolor($width, $height);
    imagecopyresampled($new_image, $image, 0, 0, 0, 0, $width, $height, $originalWidth, $originalHeight);
    					// Send the image
    					imagejpeg($image, $CACHE_FILE_PATH);
    					exit();
    			  @file_put_contents($CACHE_FILE_PATH, $output);
    			  echo $output;
    			}
    
    }
    
    
    
    
    
    
    
    if (!empty($_GET['display'])) {
    		function showimage($zip_file, $file_name) {
    			$z = new ZipArchive();
    			if ($z->open($zip_file) !== true) {
    				echo "File not found.";
    				return false;
    			}
    
    			$stat = $z->statName($file_name);
    			$fp   = $z->getStream($file_name);
    				// search for a path/to/file matching file, returning the index of it
    				$index = $z->locateName($file_name, ZipArchive::FL_NOCASE|ZipArchive::FL_NODIR);
    				// get the name of the file based on the index
    				$full_file_name = $z->getNameIndex($index);
    				// now get the stream
    				$fp = $z->getStream($full_file_name);
    
    			if(!$fp) {
    				echo "Could not load image.";
    				return false;
    			}
    
    			header('Content-Type: image/jpeg');
    			header('Content-Length: ' . $stat['size']);
    			fpassthru($fp);
    			return true;
    		}
    
    		$imgsrcencoded = $_GET['i'];
    		$imagesrc = base64_decode($imgsrcencoded);
    		$explodez = explode("#",$imagesrc);
    		$imgg = utf8_encode($explodez[1]);
    		$dirnfile = $explodez[0];
    		$zipp = end((explode('/', $dirnfile)));
    		$dirr = str_replace($zipp,"",$dirnfile);
    		$dirr = rtrim($dirr,"/");
    		$imgg = rtrim($imgg);
    		chdir($dirr);
    			if (empty($_GET['debug'])) {
    			echo showimage($zipp,$imgg);
    			}
    }
    
  5. This script will load an image (jpg, gif or png) and then save a PNG local copy for caching.

     

    I'm trying to find a way to resize the image to 300x300 before saving it as a PNG.

     

    I tried to use the function imagecopyresampled() (as you can see in the commented lines) but i get an error saying the image could not be displayed because it contains errors.

    header('Content-Type: image/png');
    
    			$imgpochette = $_GET['i'];
    
    			$ENABLE_CACHE = true;
    			$CACHE_TIME_HOURS = 744;
    			$CACHE_FILE_PATH = "pochette_album/$imgpochette.png";
    
    			if($ENABLE_CACHE && file_exists($CACHE_FILE_PATH) && (time() - filemtime($CACHE_FILE_PATH) < ($CACHE_TIME_HOURS * 60 * 60))) {
    			  echo @file_get_contents($CACHE_FILE_PATH);
    			} else {
    					// Load the requested image
    					$imgdisplay = "http://www.pirate-punk.com/pochette.php?i=$imgpochette&display=1";
    					$image = imagecreatefromstring(file_get_contents($imgdisplay));
    // $width = "30";
    // $height = "30";
    // $new_image = imagecreatetruecolor($width, $height);
    // imagecopyresampled($new_image, $image, 0, 0, 0, 0, $width, $height, $image.getWidth(), $image.getHeight());
    					// Send the image
    					imagejpeg($image, $CACHE_FILE_PATH);
    					exit();
    			  @file_put_contents($CACHE_FILE_PATH, $output);
    			  echo $output;
    			}
    
  6. Hello,

     

    Sorry for late reply, i was away from home.

     

    Here's the result:

     

     

    Could not load image.
    passed filename: 8 6 Crew - Bad Bad Reggae-front [www.Pirate-Punk.net].jpg
    files:
    86 Crew - 2000 - Bad Bad Reggae/
    86 Crew - 2000 - Bad Bad Reggae/01 - You come... [www.Pirate-Punk.net].mp3
    86 Crew - 2000 - Bad Bad Reggae/02 - Nice town [www.Pirate-Punk.net].mp3
    86 Crew - 2000 - Bad Bad Reggae/03 - Rude boy escape [www.Pirate-Punk.net].mp3
    86 Crew - 2000 - Bad Bad Reggae/04 - Prohibition [www.Pirate-Punk.net].mp3
    86 Crew - 2000 - Bad Bad Reggae/05 - R‚pression [www.Pirate-Punk.net].mp3
    86 Crew - 2000 - Bad Bad Reggae/06 - The pig [www.Pirate-Punk.net].mp3
    86 Crew - 2000 - Bad Bad Reggae/07 - Vieille France [www.Pirate-Punk.net].mp3
    86 Crew - 2000 - Bad Bad Reggae/08 - Bad bad reggae [www.Pirate-Punk.net].mp3
    86 Crew - 2000 - Bad Bad Reggae/09 - Un doute qui plane [www.Pirate-Punk.net].mp3
    86 Crew - 2000 - Bad Bad Reggae/10 - Laisses moi rˆver [www.Pirate-Punk.net].mp3
    86 Crew - 2000 - Bad Bad Reggae/11 - Harmoniska [www.Pirate-Punk.net].mp3
    86 Crew - 2000 - Bad Bad Reggae/12 - Emeute [www.Pirate-Punk.net].mp3
    86 Crew - 2000 - Bad Bad Reggae/13 - Worcking class heros [www.Pirate-Punk.net].mp3
    86 Crew - 2000 - Bad Bad Reggae/14 - Un r“le … jouer [www.Pirate-Punk.net].mp3
    86 Crew - 2000 - Bad Bad Reggae/8 6 Crew - Bad Bad Reggae-front [www.Pirate-Punk.net].jpg
    86 Crew - 2000 - Bad Bad Reggae/AlbumArtSmall [www.Pirate-Punk.net].jpg
    86 Crew - 2000 - Bad Bad Reggae/Folder [www.Pirate-Punk.net].jpg
    86 Crew - 2000 - Bad Bad Reggae/Thumbs.db

     

    The filename inside the archive and the passed filename seems to be exactly the same thing... I'm really confused.

  7. This script will find a zip archive in a specific folder, then read an image file inside the zip and output it as jpg. It works perfectly when using a simple image filename, but as soon as the image file has special characters it returns an error "could not load image".

    Here's the code:

    <?php
    function showimage($zip_file, $file_name) {
        $z = new ZipArchive();
        if ($z->open($zip_file) !== true) {
            echo "File not found.";
            return false;
        }
    
        $stat = $z->statName($file_name);
        $fp   = $z->getStream($file_name);
        if(!$fp) {
            echo "Could not load image.";
            return false;
        }
    
        header('Content-Type: image/jpeg');
        header('Content-Length: ' . $stat['size']);
        fpassthru($fp);
        return true;
    }
    
    $imgsrcencoded = $_GET['i'];
    $imagesrc = base64_decode($imgsrcencoded);
    $explodez = explode("#",$imagesrc);
    $imgg = utf8_encode($explodez[1]);
    $dirnfile = $explodez[0];
    $zipp = end((explode('/', $dirnfile)));
    $dirr = str_replace($zipp,"",$dirnfile);
    $dirr = rtrim($dirr,"/");
    $imgg = urlencode(rtrim($imgg));
    // $zipp = urlencode($zipp);
    chdir($dirr);
        if (empty($_GET['debug'])) {
        echo showimage($zipp,$imgg);
        // echo showimage("jpg.zip","test.jpg");
        }
    
    
    
    
    // debug
    if (!empty($_GET['debug'])) {
    echo "
    base64 query = $imgsrcencoded<br>
    decoded query = $imgsrc<br>
    zipp = $zipp<br>
    imgg = $imgg<br>
    dirr = $dirr<br>
    current directory = ";
    echo getcwd();
    }
    ?>


    And here's what my debug returns:

     

    base64 query = ZGwvcHAvNjI1MC84NiBDcmV3IC0gMjAwMCAtIEJhZCBCYWQgUmVnZ2FlLnppcCM4IDYgQ3JldyAtIEJhZCBCYWQgUmVnZ2FlLWZyb250ICBbd3d3LlBpcmF0ZS1QdW5rLm5ldF0uanBnCg==

    decoded query = dl/pp/6250/86 Crew - 2000 - Bad Bad Reggae.zip#8 6 Crew - Bad Bad Reggae-front [www.Pirate-Punk.net].jpg

    zipp = 86 Crew - 2000 - Bad Bad Reggae.zip

    imgg = 8+6+Crew+-+Bad+Bad+Reggae-front++%5Bwww.Pirate-Punk.net%5D.jpg

    dirr = dl/pp/6250

    current directory = /var/www/clients/client2/web1/web/dl/pp/6250


    So as you can see the script correctly switch to the corresponding directory and it is able to open the zip archive but it fails when come the time to read the JPG file if the filename has special characters

    I tried with or without utf8_encode() on the image's filename, i tried with or without urlencode() or rawurlencode() but i always get the same result...

    any suggestion ? i'm desperate.
  8. @AbraCadaver: not working :(

     

    @Barand: the problem is that the script returns incomplete filenames.

     

    If i have a file called "test123456789.zip" on my server and i use the script to search for "test12345" it will return 1 match but the script will print "test12345" instead of printing "test123456789.zip"

     

    Not sure how i could use realpath() to get the full filename of "test12345"

  9. This script will search my server for files starting by a specific string, then return the download links. Search query is defined by "f" GET value.

     

    Now let's say that i have the following files on my server:

     

    /folder/example file number one.zip

    /folder/example file number two.zip

    /folder/example file number three.zip

     

    If i search for "example file" then the script will return 3 results BUT every download links will be "/folder/example file" instead of the FULL filename.

     

    This will also create a bug with the filesize() function at the end of the script, since filesize() will look for the size of "/folder/example file" instead of using the full filename

     

    Can you help me to fix that ?

    $request = $_GET['f'];
    $adr = $_SERVER['QUERY_STRING'];
    $decode = rawurldecode(substr($adr, 2));
    
    echo "Searching for $decode";
    
    // finding the file on the server
    	$root = $_SERVER['DOCUMENT_ROOT'];
    	$search = preg_quote(utf8_decode($decode));
    
    		function rsearch($folder, $pattern) {
    			$dir = new RecursiveDirectoryIterator($folder);
    			$ite = new RecursiveIteratorIterator($dir);
    			$files = new RegexIterator($ite, $pattern, RegexIterator::GET_MATCH);
    			$fileList = array();
    			foreach($files as $file) {
    				$fileList = array_merge($fileList, $file);
    			}
    			return $fileList;
    		}
    		$resultatss = rsearch($root, '/.*\/'.$search.'/');
    
    
    foreach ($resultatss as $resultat) {
    $downloadlink = str_replace("$root/", "", $resultat);
    $pos = strrpos($downloadlink, '/') + 1;
    $encodedownloadlink = substr($downloadlink, 0, $pos) . rawurlencode(substr($downloadlink, $pos));
    
    	if (!empty($downloadlink)) {
    	echo "download link = http://www.mydomain.com/$encodedownloadlink";
    	} else {
    	echo "File not found";
    	}
    
    	$taillekb = filesize($downloadlink) / 1024;
    	echo "<br>Size: $taillekb KB<br>";
    }
    

    Thanks a lot!

  10. Ok i figured out how to install phpize, now this is what i am getting when trying to run "pecl -v install rar"

     

     

    checking how to run the C++ preprocessor... /lib/cpp
    configure: error: in `/var/tmp/pear-build-root/rar-3.0.1':
    configure: error: C++ preprocessor "/lib/cpp" fails sanity check
    See `config.log' for more details
    rolling back 388 file operations
    ERROR: `/tmp/pear/temp/rar/configure' failed
    root@ks3272412:~# configure: error: in `/var/tmp/pear-build-root/rar-3.0.1':
     

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.