Following my earlier learning of uploading files, this is what I have come up with.
<?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 ( empty( $fupload ) OR ( $fupload_type == "image/pjpeg" && $MAX_FILE_SIZE <= "51200" ))
{
$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() );
$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");
}
else
{
if ( $MAX_FILE_SIZE > "51200" )
print "File size beyond maximum size of 51,200 bytes - ($fupload_size bytes)";
elseif ( $fupload_type != "image/pjpeg" )
print "Invalid file type $fupload_type. Please submit only pjepg images (with extensions .jpg / .jpeg)";
else
{
print "Failed - reason unknown.";
}
exit;
}
?>
BUT.... I can't make the if statement return true when no file is to be uploaded.
I've tried:
if ( !isset( $fupload ) OR ( $fupload_type == "image/pjpeg" && $MAX_FILE_SIZE <= "51200" ))
and
if ( !$fupload OR ( $fupload_type == "image/pjpeg" && $MAX_FILE_SIZE <= "51200" ))
But not having any success - is there something else 'm doing wrong???
The error I returned is:
path: none
name:
size: 0 bytes
type: application/octet-stream
Invalid file type application/octet-stream. Please submit only pjepg images (with extensions .jpg / .jpeg)
Thanks in advance