Wednesday, January 16, 2008

Proxy Detector

<?
/**
* Proxy Detector v0.1
* copyrights by: Daantje Eeltink (me@daantje.nl)
* http://www.daantje.nl
*
* first build: Mon Sep 18 21:43:48 CEST 2006
* last build: Tue Sep 19 10:37:12 CEST 2006
*
* Description:
* This class can detect if a visitor uses a proxy server by scanning the
* headers returned by the user client. When the user uses a proxy server,
* most of the proxy servers alter the header. The header is returned to
* PHP in the array $_SERVER.
*
* License:
* GPL v2 licence. (http://www.gnu.org/copyleft/gpl.txt)
*
* Support:
* If you like this class and find it usefull, please donate one or two
* coins to my PayPal account me@daantje.nl
*
* Todo:
* Add open proxy black list scan.
*/

class proxy_detector {

/**
* CONSTRUCTOR
* Set defaults...
*/
function proxy_detector(){
$this->config = array();
$this->lastLog = "";

//set default headers
$this->scan_headers = array(
'HTTP_VIA',
'HTTP_X_FORWARDED_FOR',
'HTTP_FORWARDED_FOR',
'HTTP_X_FORWARDED',
'HTTP_FORWARDED',
'HTTP_CLIENT_IP',
'HTTP_FORWARDED_FOR_IP',
'VIA',
'X_FORWARDED_FOR',
'FORWARDED_FOR',
'X_FORWARDED',
'FORWARDED',
'CLIENT_IP',
'FORWARDED_FOR_IP',
'HTTP_PROXY_CONNECTION'
);
}


/**
* VOID setHeader( STRING $trigger )
* Set new header trigger...
*/
function setHeader($trigger){
$this->scan_headers[] = $trigger;
}


/**
* ARRAY $triggers = getHeaders( VOID )
* Get all triggers in one array
*/
function getHeaders(){
return $this->scan_headers;
}


/**
* VOID setConfig( STRING $key, STRING $value)
* Set config line...
*/
function setConfig($key,$value){
$this->config[$key] = $value;
}


/**
* MIXED $config = getConfig( [STRING $key] )
* Get all config in one array, or only one config value as a string.
*/
function getConfig($key=''){
if($key)
return $this->config[$key];
else
return $this->config;
}


/**
* STRING $log = getLog( VOID )
* Get last logged information. Only works AFTER calling detect()!
*/
function getLog(){
return $this->lastLog;
}


/**
* BOOL $proxy = detect( VOID )
* Start detection and return true if a proxy server is detected...
*/
function detect(){
$log = "";

//scan all headers
foreach($this->scan_headers as $i){
//proxy detected? lets log...
if($_SERVER[$i])
$log.= "trigger $i: ".$_SERVER[$i]."\n";
}

//let's do something...
if($log){
$log = $this->lastLog = date("Y-m-d H:i:s")
."\nDetected proxy server: "
.gethostbyaddr($_SERVER['REMOTE_ADDR'])." ({$_SERVER['REMOTE_ADDR']})\n".$log;

//mail message
if($this->getConfig('MAIL_ALERT_TO'))
mail($this->getConfig('MAIL_ALERT_TO'),"
Proxy detected at {$_SERVER['REQUEST_URI']}",$log);

//write to file
$f = $this->getConfig('LOG_FILE');
if($f){
if(is_writable($f)){
$fp = fopen($f,'a');
fwrite($fp,"$log\n");
fclose($fp);
}else{
die("<strong>Fatal Error:</strong> Couldn't write to file:
'<strong>$f</strong>'<br>
Please check if the path exists and is writable for the webserver or php...");
}
}

//done
return true;
}

//nope, no proxy was logged...
return false;
}
}

?>






Browsing the code you will notice that it uses a log file to store the data so we will have to create one called "
proxy_detector.log". Don't forget to give it the proper permission on the server (CHMOD it to make it writable).



Ok so we already have 2 files. Let's go ahead and create a new one called "proxy_detector.inc.php"
.This one will initiate our class for our future use and do what we want it to do so I suggest you to edit it to suit your needs. Copy paste this code and save it:



<?
/**
* Proxy Detector v0.1
* Implementation example.
*
* Mon Sep 18 23:29:47 CEST 2006
* by: me@daantje.nl
*
* Documentation:
* I use this file as an include at the top of some php files
* to block proxy users from the scripts that included this file.
*
* This file is only an example on how to implement the detector class.
* But it could be usefull as is...
*
* Check the remarks in the class for more documentation.
*/

//include detector class, assuming it's in the same directory as this file...
include_once(dirname(__FILE__)."/proxy_detector.class.php");

//init class
$proxy = new proxy_detector();

//set optional extra triggers, no need to...
//I think I've got all of them covered in the class...
// $proxy->setTrigger('HTTP_SOME_HEADER_1');
// $proxy->setTrigger('HTTP_SOME_HEADER_2');

//set optional config
// $proxy->setConfig('MAIL_ALERT_TO','me@daantje.nl');
// $proxy->setConfig('LOG_FILE','/home/daantje/public_html/proxy/proxy_detector.log');

//start detect
if($proxy->detect()){

//returned true, lets die...
echo "<h1>Proxy detected</h1>";
echo "
Please disable your proxy server in your browser preferences or internet settings,
and try again.<br><br>";

//parse logged info
echo nl2br($proxy->getLog());

//some credits...
echo "<hr><strong>proxy detector v0.1</strong>
- &copy;2006 < a href=\"http://www.daantje.nl\"
target=\"_blank\">daantje.nl</a>";

//and do nothing anymore! (but not in my example)
//exit();
}

//else, proceed as normal, put your code here...
?>

Friday, December 28, 2007

DOM / AJAX


function view_detail(id) {
// delete detail rows


// create a new row with one cell in it
var main_table = document.getElementsByTagName('table')[0];
var table_row = document.getElementById('tr'+id);

var row_index = table_row.rowIndex;
var new_row = main_table.insertRow(row_index+1);
var cell_a = new_row.insertCell(0);
cell_a.colSpan = "7";


// create a input box
var textbox = document.createElement('input');
textbox.type = 'text';
textbox.name = 'txtRow' + id;
textbox.id = 'txtRow' + id;
textbox.size = 220;
cell_a.appendChild(textbox);

// trigger Ajax
xHRObject.onreadystatechange = getData(id);
xHRObject.open("GET", "log_detail.php?id="+id, false);
xHRObject.send(null);

}

function getData(id){
if ((xHRObject.readyState==4) && (xHRObject.status==200))
{
alert("yap");
var textbox = document.getElementById('txtRow'+id);
textbox.value = xHRObject.responseText;
}
}

Saturday, December 1, 2007

10 Trick in CSS design

1. CSS font shorthand rule

When styling fonts with CSS you may be doing this:
font-size: 1em;
line-height: 1.5em;
font-weight: bold;
font-style: italic;
font-variant: small-caps;
font-family: verdana,serif;

There's no need though as you can use this CSS shorthand property:
font: 1em/1.5em bold italic small-caps verdana,serif

Much better! Just a couple of words of warning: This CSS shorthand version will only work if you're specifying both the font-size and the font-family. Also, if you don't specify the font-weight, font-style, or font-varient then these values will automatically default to a value of normal, so do bear this in mind too.
2. Two classes together

Usually attributes are assigned just one class, but this doesn't mean that that's all you're allowed. In reality, you can assign as many classes as you like! For example:
<p class="text side">...</p>

Using these two classes together (separated by a space, not with a comma) means that the paragraph calls up the rules assigned to both text and side. If any rules overlap between the two classes then the class which is below the other in the CSS document will take precedence.
3. CSS border default value

When writing a border rule you'll usually specify the colour, width and style (in any order). For example, border: 3px solid #000 will give you a black solid border, 3px thick. However the only required value here is the border style.

If you were to write just border: solid then the defaults for that border will be used. But what defaults? Well, the default width for a border is medium (equivalent to about 3 to 4px) and the default colour is that of the text colour within that border. If either of these are what you want for the border then you can leave them out of the CSS rule!
4. !important ignored by IE

Normally in CSS whichever rule is specified last takes precedence. However if you use !important after a command then this CSS command will take precedence regardless of what appears after it. This is true for all browsers except IE. An example of this would be:
margin-top: 3.5em !important; margin-top: 2em

So, the top margin will be set to 3.5em for all browsers except IE, which will have a top margin of 2em. This can sometimes come in useful, especially when using relative margins (such as in this example) as these can display slightly differently between IE and other browsers.

(Many of you may also be aware of the CSS child selector, the contents of which IE ignores.)
5. Image replacement technique

It's always advisable to use regular HTML markup to display text, as opposed to an image. Doing so allows for a faster download speed and has accessibility benefits. However, if you've absolutely got your heart set on using a certain font and your site visitors are unlikely to have that font on their computers, then really you've got no choice but to use an image.

Say for example, you wanted the top heading of each page to be ‘Buy widgets’, as you're a widget seller and you'd like to be found for this phrase in the search engines. You're pretty set on it being an obscure font so you need to use an image:
<h1><img src="widget-image.gif" alt="Buy widgets" /></h1>

This is OK but there's strong evidence to suggest that search engines don't assign as much importance to alt text as they do real text (because so many webmasters use the alt text to cram in keywords). So, an alternative would be:
<h1><span>Buy widgets</span></h1>

Now, this obviously won't use your obscure font. To fix this problem place these commands in your CSS document:
h1
{
background: url(widget-image.gif) no-repeat;
}

h1 span
{
position: absolute;
left:-2000px;
}

The image, with your fancy font, will now display and the regular text will be safely out of the way, positioned 2000px to the left of the screen thanks to our CSS rule.
6. CSS box model hack alternative

The box model hack is used to fix a rendering problem in pre-IE 6 browsers, where by the border and padding are included in the width of an element, as opposed to added on. For example, when specifying the dimensions of a container you might use the following CSS rule:
#box
{
width: 100px;
border: 5px;
padding: 20px;
}

This CSS rule would be applied to:
<div id="box">...</div>

This means that the total width of the box is 150px (100px width + two 5px borders + two 20px paddings) in all browsers except pre-IE 6 versions. In these browsers the total width would be just 100px, with the padding and border widths being incorporated into this width. The box model hack can be used to fix this, but this can get really messy.

A simple alternative is to use this CSS:
#box
{
width: 150px;
}

#box div
{
border: 5px;
padding: 20px;
}

And the new HTML would be:

<div id="box"><div>...</div></div>

Perfect! Now the box width will always be 150px, regardless of the browser!
7. Centre aligning a block element

Say you wanted to have a fixed width layout website, and the content floated in the middle of the screen. You can use the following CSS command:
#content
{
width: 700px;
margin: 0 auto;
}

You would then enclose <div id="content"> around every item in the body of the HTML document and it'll be given an automatic margin on both its left and right, ensuring that it's always placed in the centre of the screen. Simple... well not quite - we've still got the pre-IE 6 versions to worry about, as these browsers won't centre align the element with this CSS command. You'll have to change the CSS rules:
body
{
text-align: center;
}

#content
{
text-align: left;
width: 700px;
margin: 0 auto;
}

This will then centre align the main content, but it'll also centre align the text! To offset the second, probably undesired, effect we inserted text-align: left into the content div.
8. Vertically aligning with CSS

Vertically aligning with tables was a doddle. To make cell content line up in the middle of a cell you would use vertical-align: middle. This doesn't really work with a CSS layout. Say you have a navigation menu item whose height is assigned 2em and you insert this vertical align command into the CSS rule. It basically won't make a difference and the text will be pushed to the top of the box.

Hmmm... not the desired effect. The solution? Specify the line height to be the same as the height of the box itself in the CSS. In this instance, the box is 2em high, so we would insert line-height: 2em into the CSS rule and the text now floats in the middle of the box - perfect!
9. CSS positioning within a container

One of the best things about CSS is that you can position an object absolutely anywhere you want in the document. It's also possible (and often desirable) to position objects within a container. It's simple to do too. Simply assign the following CSS rule to the container:
#container
{
position: relative;
}

Now any element within this container will be positioned relative to it. Say you had this HTML structure:

<div id="container"><div id="navigation">...</div></div>

To position the navigation exactly 30px from the left and 5px from the top of the container box, you could use these CSS commands:
#navigation
{
position: absolute;
left: 30px;
top: 5px;
}

Perfect! In this particular example, you could of course also use margin: 5px 0 0 30px, but there are some cases where it's preferable to use positioning.
10. Background colour running to the screen bottom

One of the disadvantages of CSS is its inability to be controlled vertically, causing one particular problem which a table layout doesn't suffer from. Say you have a column running down the left side of the page, which contains site navigation. The page has a white background, but you want this left column to have a blue background. Simple, you assign it the appropriate CSS rule:
#navigation
{
background: blue;
width: 150px;
}

Just one problem though: Because the navigation items don't continue all the way to the bottom of the screen, neither does the background colour. The blue background colour is being cut off half way down the page, ruining your great design. What can you do!?

Unfortunately the only solution to this is to cheat, and assign the body a background image of exactly the same colour and width as the left column. You would use this CSS command:
body
{
background: url(blue-image.gif) 0 0 repeat-y;
}

This image that you place in the background should be exactly 150px wide and the same blue colour as the background of the left column. The disadvantage of using this method is that you can't express the left column in terms of em, as if the user resizes text and the column expands, it's background colour won't.

At the time of writing though, this is the only solution to this particular problem so the left column will have to be expressed in px if you want it to have a different background colour to the rest of the page.

Tuesday, November 20, 2007

Transfer Deprecated HTML Attributes to CSS

type

The type attribute was used to set the list markers on unordered and ordered lists (#ul> and #ol>) and on individual list items (#li>) for example “a, b, c”, “1, 2, 3″, “i, ii, iii”, etc.

#ol type="a">
#li>First item#/li>
#li>Second item#/li>
#li>Third item#/li>
#/ol>

1. First item
2. Second item
3. Third item

Deprecated example of “type” in an ordered list element

To replicate this in CSS you must use list-style-type:

ol { list-style-type: lower-alpha; }

This styling can also be used on individual #li> elements to create differing sequence types, if you really wanted to!

Using the HTML attributes there were only 5 possible types you could use (1, A, a, I and i). By using CSS this increases to a possible 20 values including types such as “hiragana-iroha”, which is a Japanese sequence, and “none” to stop displaying any kind of sequence or bullet. An example of all the types can be seen if you are viewing the page using Firefox - unfortunately IE doesn’t recognise any of the more complex character types and will default to the list’s own style type.

border

The border attribute was deprecated only on the #img /> and #object> elements, but this should be used anywhere that you’d like to modify a border - to further the separation of presentation and content.

The most common place you’ll see this attribute, in current use, is on images that are surrounded by a link:

#a href="#">
#img src="images/cup.gif" width="10"
height="20" border="0" />
#/a>

Deprecated example of “border” in the image element

Without setting the border to zero, the browser’s default and usually undesirable rendering is to place an blue border around the image, to show that it is clickable (much like it will add a blue underline to a text link).

You will probably want to remove the border from all images that fall inside a link, using CSS you do this using the “border” declaration:

a img { border: 0; }
// you could also use border:none;

The flexibility in using CSS in favour of the deprecated attribute is similar to the hspace/vspace example above. It is now very easy to specify a different border size, colour and style to each different side of the item.

img {
border-width: 2px 4px;
border-style:dotted dashed solid none;
border-color: red;
}
// width: top and bottom 2px, left and right 4px
// style: top dotted, right dashed,
bottom solid, left none
// color: all sides red, if present

size

Size was in use on the #hr /> (horizontal rule) element to set it’s height in pixels or percentage. Years ago I would always set size to 1 to give a thin solid black line, which would get rid of the default two-tone shading effect - more on the shading of #hr /> later.

#hr size="1" />
#hr size="5%" />

Before I show how to replicate this using CSS, I should point out that there are continual wranglings about whether or not this whole tag should still be in use. The two sides to the argument are; on the one hand it is a purely presentational element and should be removed in favour of using a border declaration in CSS; and on the other hand it has its semantic place to divide sections of text. I will leave the decision to you - a huge discussion on #hr />’s semantics took place on the Web Standards Group list last week.

To replicate in CSS is simple and uses the “height” declaration:

hr { height:1px; }
hr { height:5%; }

By moving this to CSS we again open up the possibilities of how a horizontal rule can be styled - adding colour, relative heights and background images (note: the rendering of background images and colour is not consistent across the browsers).

noshade

The #hr /> element had another attribute deprecated; noshade was a boolean attribute used to remove the two-tone shading effect and set the line in a solid colour, usually grey.

#hr noshade />

As a small aside, boolean attributes in XHTML are no longer used in their shortened form. For example, the “checked” attribute that is still in use on #input type=”checkbox” /> elements should be written in long-hand:

#input type="checkbox" checked="checked" />

Similarly for “selected” in #option> elements:

#option selected="selected" >Option 1#/option>

Removing the shade in CSS isn’t as straight-forward as the attributes we’ve seen so far. In IE you’ll need to use the “color” declaration; and in Mozilla and Opera you need to use both the “border” and “background-color” declarations to get a similar effect to the original attributes. The following should be safe across different browers.

hr {
color: gray; // for IE
background-color: gray; // for Mozilla and Firefox
border: 0; // for Mozilla and Firefox
}

The same styling rules apply as for the “size” attribute above.

width and height

The width attribute was deprecated for use on #th>, #td> and #hr />, and the height attribute on #th> and #td>. I hope it’s obvious that they set the width and height of the element on which they are specified, quoted in pixels or percentage.

#td width="50%" height="20px">Umbrella stand#/td>

Deprecated example of “width” and “height” in a table data element

In the old days of table-based layouts, width and height would be littered around a page’s code hugely increasing the byte size of the file. Removing them gives you a huge saving in bandwidth and simplifies the code for easier maintenance. In CSS you’d replace these attributes in the following way:

td {
width: 50%;
height: 20px;
}

bgcolor

Bgcolor was an attribute used to set the background colour of the #table> elements and the #body> element. It would be used to set the background colour of the whole page, you can use a named value or hex if necessary:

#body bgcolor="purple">

Or to set individual rows or cells of tables:

#table>
#tr bgcolor="pink">
#td>The pink row#/td>
#td>Still the pink row#/td>
#/tr>
#tr>
#td bgcolor="green">The green cell#/td>
#td>No colour#/td>
#/tr>
#/table>

In CSS the property is “background-color” (to colour individual rows/cells you would need to add a class or id to those rows):

body { background-color: purple; }
tr.odd { background-color: pink; }
td.highlight { background-color: green; }

Moving this to CSS gives you so much more control over the way pages and tables look. There are a whole host of background related CSS properties such as “background-image”, “background-position”, “background-attachment” and “background-repeat”; these can be grouped together using the background shorthand:

background: color | image | repeat | attachment | position ;

So if you had a flower image that you wanted to appear at the bottom right of all pages on your site you’d use the “background” declaration to set this up in one line;

body { background: white url(imgs/flower.jpg) no-repeat right bottom; }

align

The align attribute was used to specify the horizontal alignment of an element with the surrounding content. Now it should not be used on any element but you still see it used mainly on the #img />, #hx> and #p> elements:

#h1 align="center">Centred heading#/h1>
#p align="justified">Bit of text that should be justified.#/p>

Deprecated example of “align” in the h1 and p elements

The equivalent CSS property is text-align and has the same values as the align attribute; left, right, center and justified.

h1 { text-align: center; }
p { text-align: justified; }

The thing to remember with this property is that it can align any element and not just text, as it seems to imply.

For reference; CSS2 introduced another value for text-align, which is “#string>” and for use in tables only. It aligns the text to whatever string value you enter, for example td { text-align: "."; } could be used to align a column of numerical data on the decimal point. It was withdrawn from CSS2.1 due to lack of implentation among the browsers.
End

The main thing to remember is that it is always better to remove all presentational attributes from your (X)HTML code and use CSS to do the same job. There’s a CSS declaration for any HTML attribute, so remove them all for best results.
Additional Resources

W3 Schools: this is the site I started learning from
HTML Dog: excellent resource, written by a pro
CSS Zen Garden/: the original CSS playground, great for inspiration and pushing the limits of what CSS can do for you

Sunday, November 18, 2007

Dynamic Chart Drawn by JpGraph

Load data from database to JpGraph

1、
copy
example16.2.php from ./src/Examples
and
jpgraph_bar.php、 jpgraph_gradient.php、jpgraph_line.php、jpgraph_plotmark.inc、jpgraph.php from ./src
to current folder

2、create database name: jpg,Table: test
two fields:
id(Key):int
number:int
add some data

3、Modify example16.2.php

#?php
include ("jpgraph.php");
include ("jpgraph_line.php");
include ("jpgraph_bar.php");

$connect=mysql_connect("localhost","root","");
mysql_select_db("jpg",$connect);
$query=mysql_query("select * from test",$connect);
$i=0;
while ($array=mysql_fetch_array($query)) {
$l2datay[$i]=$array["number"];
$i++;
}
mysql_close($connect);

// Create the graph.
$graph = new Graph(400,200,"auto");
$graph->SetScale("textlin");

$graph->img->SetMargin(40,130,20,40);
$graph->SetShadow();

// Create the bar plot
$bplot = new BarPlot($l2datay);
$bplot->SetFillColor("orange");
$bplot->SetLegend("Result");

// Add the plots to t'he graph

$graph->Add($bplot);

$graph->title->Set("Adding a line plot to a bar graph v1");
$graph->xaxis->title->Set("X-title");
$graph->yaxis->title->Set("Y-title");

$graph->title->SetFont(FF_FONT1,FS_BOLD);
$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);

//$graph->xaxis->SetTickLabels($datax);
//$graph->xaxis->SetTextTickInterval(2);

// Display the graph
$graph->Stroke();
?>

Friday, November 16, 2007

mount ISO in Linux

在#提示符下执行命令
cp /dev/cdrom XXXXX.iso
XXXXX.iso即为需要命名的ISO文件名
执行之后,光盘上所有文件就被映射成XXXXX.iso
至于如何加载请看下面,
还是在#提示符下执行命令
rm -rf /dev/cdrom
ln -s /dev/loop7 /dev/cdrom
losetup /dev/loop7 /PATH(iso文件路径)
mount /mnt/cdrom
如果需要换盘
losetup -d /dev/loop7
再重复
losetup /dev/loop7 /PATH(iso文件路径)
mount /mnt/cdrom
如果是普通含有iso的光盘
可以直接使用命令
mount -t iso9660 -o loop /../*.iso /path
/.../*.iso 是iso文件路径
/path 是挂载点

Tuesday, October 23, 2007

Upload Image


<?
if(isset($_POST['submit'])) { //see if submit button is pressed.

//check if they decided to upload a pic:
if($_FILES['userfile']['size'] > 1) {

$max_size = 100000;
$max_height = 300;
$max_width = 300;

$info = getimagesize($_FILES['userfile']['tmp_name']);

//check file-size (in bytes):
if(($_FILES['userfile']['size'] > $_POST['MAX_FILE_SIZE']) ||
($_FILES['userfile']['size'] > $max_size)) {
die("<BR><BR>Error: Upload file size too large: (<b>" .
$_FILES['userfile']['size'] . "</b>). Must not exceed XX kb.");
}

//check the extension.
$array = explode(".", $_FILES['userfile']['name']);
$nr = count($array);
$ext = $array[$nr-1];
if(($ext !="jpg") && ($ext !="jpeg") && ($ext !="png"))
die("<BR><BR>Error: file extension un-recognized.
Be sure your image follows the correct extension (.JPG or .PNG)");

//CHECK TYPE: (what the browser sent)
if(($_FILES['userfile']['type'] != "image/jpeg") && ($_FILES['userfile']['type'] !=
"image/pjpeg") && ($_FILES['userfile']['type'] != "image/png")) {
die("<BR><BR>Error: Upload file type un-recognized. Only .JPG or .PNG
images allowed.");
}

//DOUBLE CHECK TYPE: if image MIME type from GD getimagesize()
//-In case it was a FAKE!
if(($info['mime'] != "image/jpeg") && ($info['mime'] != "image/pjpeg") &&
($info['mime'] != "image/png")) {
die("<BR><BR>Error: Upload file type un-recognized. Only .JPG or .PNG
images allowed.");
}

//check file size (length & width)
if(($info[0] > $max_width) || ($info[1] >$max_height)) {
die("<BR><BR>Error: Image size error (<b>" . $info[0] .
"</b> x <b>" . $info[1] . "</b>). Must not exceed ". $max_height .
" x ". $max_width .".");
}

//rename file, move it to location.
if(is_uploaded_file($_FILES['userfile']['tmp_name'])) {

//get max number of images the user has uploaded
$m = mysql_query("SELECT max(user_images) as `total_images`
FROM `images` WHERE `user_id` = '".$_SESSION['user_id']."'");
if(!$m) die('An Error Occurred.');
$result = mysql_fetch_object($m);
if($result->total_images <= 0) {
$image_number = 1;
} else {
$image_number = $result->total_images + 1;
} //end if

$filename = strtolower($_SESSION['username']) . $image_number;

if(move_uploaded_file($_FILES['userfile']['tmp_name'] ,
$_SERVER['DOCUMENT_ROOT']."/path/to/image/".$filename . '.' . $ext)) {
echo("File uploaded successfully.");
} else {
echo("An error occurred while uploading.");
}//end upload
} //end is_uploaded_file

} else { //display form ?>

<form enctype="multipart/form-data" action="<? $_SERVER['PHP_SELF']; ?>"
method="post" name="uploadImage" />
<input type="hidden" MAX_UPLOAD_SIZE = "10000" />
<input type="file" name="userfile" size="35" />
<input type="submit" name="submit" value="Upload Image">

<? } //end else ?>