php - Shell_Exec error for directory listing? -


i found useful php code displays photos in folder directory image preview. issue host provider blocks 1 of script commands, "shell_exec()", php code doesn't work.

any way of getting code run without using shell_exec?

<?php   // filetypes display   $imagetypes = array("image/jpeg", "image/gif"); ?> <?php    function getimages($dir)   {     global $imagetypes;      // array hold return value     $retval = array();      // add trailing slash if missing     if(substr($dir, -1) != "/") $dir .= "/";      // full server path directory     $fulldir = "{$_server['document_root']}/$dir";      $d = @dir($fulldir) or die("getimages: failed opening directory $dir reading");     while(false !== ($entry = $d->read())) {       // skip hidden files       if($entry[0] == ".") continue;        // check image files       $f = escapeshellarg("$fulldir$entry");       $mimetype = trim(`file -bi $f`);       foreach($imagetypes $valid_type) {         if(preg_match("@^{$valid_type}@", $mimetype)) {           $retval[] = array(            'file' => "/$dir$entry",            'size' => getimagesize("$fulldir$entry")           );           break;         }       }     }     $d->close();      return $retval;   } ?> <?php   // fetch image details   $images = getimages("images");    // display on page   foreach($images $img) {     echo "<div class=\"photo\">";     echo "<img src=\"{$img['file']}\" {$img['size'][3]} alt=\"\"><br>\n";     // display image file name link     echo "<a href=\"{$img['file']}\">",basename($img['file']),"</a><br>\n";     // display image dimenstions     echo "({$img['size'][0]} x {$img['size'][1]} pixels)<br>\n";     // display mime_type     echo $img['size']['mime'];     echo "</div>\n";   } ?> 

you can mime type of file using php function mime_content_type(). way can rid of shell_execute used detect mime type in code.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -