We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6726
    • 7,075 Posts
    Thanks a lot for all this !

    I didn’t include the size_readable function, where should I add it ? Just before the placeholder is set doesn’t seem to work undecided

    Here is how I changed the code, taking what you said into account I changed the placeholder names :

    	function size_readable ($size, $retstring = null) {
    		        // adapted from code at http://aidanlister.com/repos/v/function.size_readable.php
    		        $sizes = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
    		        if ($retstring === null) { $retstring = '%01.2f %s'; }
    		        $lastsizestring = end($sizes);
    		        foreach ($sizes as $sizestring) {
    		                if ($size < 1024) { break; }
    		                if ($sizestring != $lastsizestring) { $size /= 1024; }
    		        }
    		        if ($sizestring == $sizes[0]) { $retstring = '%01d %s'; } // Bytes aren't normally fractional
    		        return sprintf($retstring, $size, $sizestring);
    		}				
    				
    		$pics[$i]['title'] = stripslashes($pics[$i]['title']);
    		$pics[$i]['descr'] = stripslashes($pics[$i]['descr']);
    		$pictureTplData['picture'] = $pics[$i];
    		$pictureTplData['counter'] = $pic_number;		
    		$pictureTplData['picture_height_big'] = $imagesize[1];
        	        $pictureTplData['picture_width_big'] = $imagesize[0];
                    $pictureTplData['picture_bigsize'] = size_readable(filesize($modx->config['base_path'].$mg->path_to_gal."big_".$pics[$i]['filename']));
                    $pictureTplData['picture_normalsize'] = size_readable(filesize($modx->config['base_path'].$mg->path_to_gal . $pics[$i]['filename']));
    		$pictureTplData['picture_thumbsize'] = size_readable(filesize($modx->config['base_path'].$mg->path_to_gal."tn_".$pics[$i]['filename']));
    		
    		if(file_exists($modx->config['base_path'].$mg->path_to_gal."big_".$pics[$i]['filename'])){
    			$imagesize=getimagesize($modx->config['base_path'].$mg->path_to_gal."big_".$pics[$i]['filename']);
    			$pictureTplData['picture_height_big'] = $imagesize[1];
    			$pictureTplData['picture_width_big'] = $imagesize[0];
    			$pictureTplData['big_pic_exists'] = 1;		
    			$pictureTplData['picture_bigsize'] = size_readable(filesize($modx->config['base_path'].$mg->path_to_gal."big_".$pics[$i]['filename']));	
    		} else {
    			$pictureTplData['big_pic_exists'] = 0;
    		}
    		
    		if(file_exists($modx->config['base_path'].$mg->path_to_gal.$pics[$i]['filename'])) {
    			$imagesize=getimagesize($modx->config['base_path'].$mg->path_to_gal.$pics[$i]['filename']);
    			$pictureTplData['picture_height_normal'] = $imagesize[1];
    			$pictureTplData['picture_width_normal'] = $imagesize[0];
    			$pictureTplData['picture_normalsize'] = size_readable(filesize($modx->config['base_path'].$mg->path_to_gal . $pics[$i]['filename']));
    		}
    		
    		if(file_exists($modx->config['base_path'].$mg->path_to_gal."tn_".$pics[$i]['filename'])) {
    			$imagesize=getimagesize($modx->config['base_path'].$mg->path_to_gal."tn_".$pics[$i]['filename']);
    			$pictureTplData['picture_height_thumb'] = $imagesize[1];
    			$pictureTplData['picture_width_thumb'] = $imagesize[0];
    		    $pictureTplData['picture_thumbsize'] = size_readable(filesize($modx->config['base_path'].$mg->path_to_gal."tn_".$pics[$i]['filename']));
    		}


    Sorry for the trouble, but it still doesn’t work... huh
      .: COO - Commerce Guys - Community Driven Innovation :.


      MODx est l&#39;outil id
      • 10449
      • 956 Posts
      I put that extra function on top of everything else, right after the first <?php
        • 6726
        • 7,075 Posts
        Ok I’ll try that !

        Done : No luck there must be something wrong !

        Noticed this comment on the function’s page :
        Michael MH
        30-Aug-2007 03:28
        I just noticed, that filesize(), filemtime() etc. only work correctly on Mac OS X if the file’s directory is executable for the PHP process. Otherwise it will report "stat failed for <filepathandname>".

        I run a dedicated box and I don’t have php suExec / suPHP or whatever, could this be a ownership / CHMOD issue ?
        I know the comment was about OS X and I am running Debian 4.0 but who knows...

        It’s frustrating !
          .: COO - Commerce Guys - Community Driven Innovation :.


          MODx est l&#39;outil id
          • 10449
          • 956 Posts
          You can easily isolate the problem: Just create a standalone PHP script pointing to one of those MG images. If it works there, it should work inside the MG script as well. Add ini_set(’error_reporting’, E_ALL); to make sure all errors are reported. Seems like MG or MODx suppresses some errors.

          You could also try to chmod() directly from within the MG script: http://ch2.php.net/chmod

          And finally, maybe add &debug=`1` to your MG call.


          FYI, I tested this with:
          Apache/2.0.55 (Ubuntu) mod_jk/1.2.14 mod_python/3.1.4 Python/2.4.3 PHP/5.2.0-0.dotdeb.3 with Suhosin-Patch mod_ssl/2.0.55 OpenSSL/0.9.8a mod_perl/2.0.2 Perl/v5.8.7
          MODx 0.9.6 rev 2767
          MG 0.5.2
            • 6726
            • 7,075 Posts
            Tried adding debug=`1` to MG but it does provide very few infos...

            I have set error reporting to ALL but nothing either.
            Out of curiosity I have inserted a separate FileDetails call to check if it managed to get the file size... and it does !

            I tried to insert the formatbyte function

            if (function_exists("formatbytes") === FALSE) {
            # Format byte size according to selected mode
            # Courtesy of [email protected]
            function formatbytes($val, $digits = 3, $mode = "SI", $bB = "B"){ //$mode == "SI"|"IEC", $bB == "b"|"B"
            $si = array("", "k", "M", "G", "T", "P", "E", "Z", "Y");
            $iec = array("", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi");
            switch(strtoupper($mode)) {
            case "SI" : $factor = 1000; $symbols = $si; break;
            case "IEC" : $factor = 1024; $symbols = $iec; break;
            default : $factor = 1000; $symbols = $si; break;
            }
            switch($bB) {
            case "b" : $val *= 8; break;
            default : $bB = "B"; break;
            }
            for($i=0;$i<count($symbols)-1 && $val>=$factor;$i++)
            $val /= $factor;
            $p = strpos($val, ".");
            if($p !== false && $p > $digits) $val = round($val);
            elseif($p !== false) $val = round($val, $digits-$p);
            return round($val, $digits) . " " . $symbols[$i] . $bB;
            }
            }


            instead of the size_readable function, and tweak the placeholder this way :

            $pictureTplData[’picture_bigsize’] = formatbytes(filesize($mg->path_to_gal."big_".$pics[$i][’filename’]), 3, "SI", "B");

            instead of

            $pictureTplData[’picture_bigsize’] = size_readable(filesize($modx->config[’base_path’].$mg->path_to_gal."big_".$pics[$i][’filename’]));

            But it doesn’t work either.

            I am stuck...
            I’ll let it rest for now and see if my mind clears tomorrow...
              .: COO - Commerce Guys - Community Driven Innovation :.


              MODx est l&#39;outil id
              • 10449
              • 956 Posts
              When I said "isolate the problem", I didn’t mean the formatting function: that works 100%.

              Test the filesize() function instead.

              <?php
              echo filesize('/full/path/to/image.jpg'); // test with full path
              echo '<br />';
              echo filesize('/path/to/image.jpg'); // test with relative path
              ?>
              


              It could be that your server configuration only allows this function to access files in the same directory as your script.
                • 7231
                • 4,205 Posts
                FileDetails uses filesize($filepath) to get the size. So if it works then filepath works.

                # get file size
                $file[’filesize’] = formatbytes(filesize($filepath), $digits, $byteMode, "B");
                  [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                  Something is happening here, but you don&#39;t know what it is.
                  Do you, Mr. Jones? - [bob dylan]
                  • 6726
                  • 7,075 Posts
                  Yes and I put the mg filepath in here...

                  Ok GaneshXL I’ll try that tomorrow !
                    .: COO - Commerce Guys - Community Driven Innovation :.


                    MODx est l&#39;outil id
                    • 6726
                    • 7,075 Posts
                    Okay GaneshXL, I did put up the test file you asked :

                    <?php
                    echo filesize(’http://ns*****.ovh.net/~secusol/assets/galleries/833/big_1big_946013_53113128.jpg’); // test with full path
                    echo ’
                    ’;
                    echo filesize(’assets/galleries/833/big_1big_946013_53113128.jpg’); // test with relative path
                    ?>

                    Note that the relative filepath does NOT start with a / I tested it gives me the same warning as for full path.

                    and I get this :

                    Warning: filesize() [function.filesize]: stat failed for http://ns29452.ovh.net/~secusol/assets/galleries/833/big_1big_946013_53113128.jpg in /home/secusol/domains/soleil.info/public_html/test_filesize.php on line 2
                    
                    1243422


                    You were right on the money, it would seem it only works with relative filepaths...

                      .: COO - Commerce Guys - Community Driven Innovation :.


                      MODx est l&#39;outil id
                      • 28042 ☆ A M B ☆
                      • 24,524 Posts
                      That’s because your "full path" isn’t a path at all, it’s a URL. A path will start from your server’s file system root, such as
                      /home/domain/public_html/assets/...
                        Studying MODX in the desert - http://sottwell.com
                        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                        Join the Slack Community - http://modx.org