file uploads and sizes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



i have the following code that works except when the file i'm trying to
upload excedes the upload_max _filesize and post_max_size defined in the
php.ini file.
what happens when the file is smaller than the max sizes mentioned
previously, the if (isset .....) part of the code is executed yet when the
file exceeds both max sizes, i just get a blank page.
what id like is to be able to give the user a message saying the file wasnt
uploaded because  the file was too big.so, how do i verify the size of the
file the user is trying to upload? ive already tried
$_FILES['archivo']['size'], but that doesnt work if the variable isnt set,
which aparently happens when the file isnt uploaded because of the
post_max_size.

any help will be greatly appreciated!!

thanx.

<?


if(isset($_FILES['archivo']) &&
is_uploaded_file($_FILES['archivo']['tmp_name']))
{
 $archivo = $_FILES['archivo']['tmp_name'];

 $archivo_name = $_FILES['archivo']['name'];
 print "You uploaded a file called {$_FILES['archivo']['name']} <br></br>";
 print "of type {$_FILES['archivo']['type']} that is <br></br>";
 print "{$_FILES['archivo']['size']} bytes long.<br>";
 $safe_filename = str_replace('/', '', $_FILES['archivo']['name']);
 $safe_filename = str_replace('..', '', $safe_filename);


$dbh = pg_connect("host=localhost dbname=test user=postgres");
 if (!$dbh)
 {
  echo "cannot open connection to the database<br>";
  exit;
 }

 else {
   chmod($archivo,0777);
  pg_exec($dbh,"BEGIN");
  $sql = "INSERT INTO pic_db (name, picoid) VALUES ";
  $sql .= "('$safe_filename', lo_import('$archivo'))";
  $stat = pg_exec($dbh, $sql);
  pg_exec($dbh,"COMMIT");
  pg_close($dbh);
  echo "The file was saved succesfully.<br>";
    }

  unlink($archivo); */
}


?>

<html>
<body>
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="archivo">
</form>
</body>
</html>


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux