Try this out...
weblogadmin.html
<form action="addweblog.php" method="post" name="form1" enctype="multipart/form-data">
<table align="center">
<tr>
<td width="100" class="smalltext">Description:</td>
<td><input class="smalltext" type="text" size=40 name="description"></td>
</tr>
<tr>
<td width="100" valign=top class="smalltext">Content:</td>
<td><textarea class="smalltext" rows=5 cols=40 name="content"></textarea></td>
</tr>
<tr>
<td width="100" valign="top" class="smalltext">Upload file(s):</td>
<td><input class="smalltext" type="file" name="fupload"><input type="hidden" name="MAX_FILE_SIZE" value="51200"></td>
</tr>
<tr>
<td align="center" colspan="2">
<input class="text" type="submit" value="Submit">
</td>
</tr>
</table>
</form>
addweblog.php
<?php
$file_dir = "/users/rupertbj/domains/rupstar.co.uk/html/images/weblog";
$file_url = "http://www.rupstar.co.uk/images/weblog";
// print "path: $fupload<br>\n";
// print "name: $fupload_name<br>\n";
// print "size: $fupload_size bytes<br>\n";
// print "type: $fupload_type<p>\n\n";
if ( $fupload_type == "image/pjpeg" && $MAX_FILE_SIZE <= "51200" )
{
$db = "weblog";
$link = mysql_connect( "path/to/sql/mysql.sock", "username", "password" );
if ( !$link ) die( "Couldn't connect to MySQL".mysql_error() );
mysql_select_db( $db, $link ) or die( "Couldn't open $db: ".mysql_error() );
$sql = "INSERT INTO weblogTable VALUES ( '', now(), '$description', '$content', '$fupload_name' )";
mysql_query( $sql, $link );
mysql_close( $link );
copy ( $fupload, "$file_dir/$fupload_name" ) or die ("Couldn't copy");
}
elseif ( $fupload_size == "0" )
{
$db = "weblog";
$link = mysql_connect( "localhost:/users/rupertbj/domains/rupstar.co.uk/sql/mysql.sock", "root" );
if ( !$link ) die( "Couldn't connect to MySQL".mysql_error() );
mysql_select_db( $db, $link ) or die( "Couldn't open $db: ".mysql_error() );
$fupload_name = "No image uploaded - sorry!";
$sql = "INSERT INTO weblogTable VALUES ( '', now(), '$description', '$content', '$fupload_name' )";
mysql_query( $sql, $link );
mysql_close( $link );
}
else
{
if ( $MAX_FILE_SIZE > "51200" ){
print "File size beyond maximum size of 51,200 bytes - ($fupload_size bytes)";
exit;
}
elseif ( $fupload_type != "image/pjpeg" ){
print "Invalid file type $fupload_type. Please submit only pjepg images (with extensions .jpg / .jpeg)";
exit;
}
else
{
print "Failed - reason unknown.";
exit;
}
}
?>