Entry 2993

gallery code

   

Submitted by cherudek on Jan. 13, 2010 at 9:46 p.m.
Language: PHP. Code size: 2.0 KB.

<?php
$mydir = "path/to/dir/"; //define working dir
$d = dir($mydir); //define dir content
while($entry = $d->read()) { //while dir reads something, do...
    if ($entry != "." && $entry != "..") { //exclude . and ..
	$projname = remext($entry); //remove extension with a custom function
	$did = "path/to/txt-dir/".$projname.".txt"; //define txt path and name
	$arrdid = file($did); //gets txt file content and put it in an array
	$thumb = "path/to/thumbnails-dir/".$projname.".jpg"; //define thumbnail path
	$itemurl = $mydir.$entry; // define image url
	$imgsize = filesize($itemurl)/(1024*1024); // get the image size in MB
	$r_imgsize = round($imgsize, 2); //round to second decimal
	echo "<h5>".$arrdid[0]."</h5>\n"; //print out the title (first line) from txt
	//place image, image size and some tags:
	echo "<table border=\"0\"><tr><td class=\"did\"> \n 
	      <a href=\"".$itemurl."\">
	      <img class=\"gall\" src=\"".$thumb."\" alt=\"".$arrdid[0]."\"/>
	      </a> \n<br />
	      <span class=\"deco2\">".$r_imgsize." MB</span></td>
	      <td class=\"did\"> \n";
	foreach($arrdid as $linenum => $words) { //print the text but the first line
	    if ($linenum != 0) {
		echo $words."<br />\n";
	    }
	}
	$blend = "path/to/blends-dir/".$projname.".blend"; //define blend path
	$arch = "path/to/archives-dir/".$projname.".tar.gz"; //define archive path
	if (file_exists($blend)) { //if blend file exists, print out link and size
	    $blendsize = filesize($blend)/(1024*1024); //get the blend size in MB
	    $r_blendsize = round($blendsize, 2); //round to second decimal
	    echo "<br />Download the <a href=\"".$blend."\">.blend file</a>
		  (<span class=\"deco2\">".$r_blendsize." MB</span>). \n";
	}
	if (file_exists($arch)) {
	    $archsize = filesize($arch)/(1024*1024);
	    $r_archsize = round($archsize, 2);
	    echo "<br />Download the <a href=\"".$arch."\">scene stuff</a>
		  (<span class=\"deco2\">".$r_archsize." MB</span>). \n";
	}
	echo "</td></tr></table><br />\n";
    }
}
$d->close(); //close dir
?>

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).