cornerhost wiki   DragnDrop UserPreferences
 
HelpContents FindPage Diffs Info Edit Subscribe XML Print View

back to PhpPrentice

Purpose

As a designer, I am constantly working on print projects, and rarely take time to update my portfolio site. The goal was to build a script for updating my portfolio with "drag and drop" ease of use.

What Success Looks Like

Here is the outcome I was looking for: in order to add a project description page for a new project, all I want to do was add "newproject.jpg" "newproject.txt" and "newproject.html" to the server. Then, "newproject.html" will recognize the contents of "newproject.txt" as the project description, and "newproject.jpg" as the project thumbnail. The rest of "newproject.html" will contain the same html content as all other project description pages on the site. This script was tailored for a "picture gallery" style site.

The Script

<?php

#get the enviroment variable of the current page.
#if you're going to me.com/site/test/whatever.php
#then this is /site/test/whatever.php

$script=$_SERVER['SCRIPT_NAME'];

#get the name of the directory
#which is just "/site/test" (no trailing "/")

$dir=dirname($script);

#replace "/site/test" and the trailing "/" with ""
#the ^ means 'start at the begining of the string in this context

$file=ereg_replace("^$dir/","",$script);

#replace the ".php" at the end of the file name with ""
#the \ is to escape the . since a . by itself means "any character"
#and we want a literal .

$name=ereg_replace("\.php$","",$file);

#name is now just "whatever" so you can play with it to your
#heart's content by including "whatever.txt" from the same dir include("$name.txt");
#since your result will be html, you may wish to put code around the
#include to mark it up so you can stick to just raw content in your .txt
#file.
#or linking to "whatever.jpg"
?>

<hr>

<img src="<?=$name?>.jpg">
#Jpegs of each project show up on using this naming convention in the html

<a href="<?=$name?>.pdf">
#Higher resolution PDFs of each project are linked in the template with this naming convention in the html

This script was masterfully written by [WWW]Phillip Harrington and additionally modified by [WWW]Al-Insan Lashley

Success

The script worked great. I uploaded a _template.php file, then copied it and renamed it after one of my projects: "cmba.php." I uploaded a preview jpg named "cmba.jpg" and a paragraph of content named "cmba.txt."

The page can be found at: [WWW]alinsan.net

The Kinks

None. New version of my web site (12.29.2006) I'm using this method for the archive and main page of my site.

back to PhpPrentice

PythonPowered