Hi, I'm using a filesize() function I saw online (see very bottom of script) and it keeps generating the following error...
Warning: filesize() [function.filesize]: stat failed for example.jpg
Apparently this happens if it's not writeable, however if I take out the check and stick in the code to upload the file it uploads without any problems.
What the script should do is redirect to an error page should the file be larger than 50kb, if not it should just end and do nothing (at least for now).
Does anyone have any idea? I took the filesize bit from here http://www.zymic.com/tutorials/php/creating-a-file-upload-form-with-php/ and nobody else seems to be reporting the same error.
<?php
$target_path = "images/uploads/";
$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['password'];
$quote = $_POST['quote'];
$filename = $_FILES['uploadedfile']['name'];
$allowed_filetypes = array('jpg','gif','bmp','png');
$date = date("Y-m-d");
$max_filesize = 55000;
// Checks all fields have been completed.
if (!trim($username) || !trim($email) || !trim($password) || !trim($quote)) {
header('Location: error.php?code=1');
exit();
}
else{
include("config.php");
$connect = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Ah **** - MySQL error!');
mysql_select_db($dbname) or die ('Ah **** - MySQL error!');
// Checks username hasn't already been taken
$query = mysql_query("SELECT username FROM members WHERE username = '$username'");
$check = mysql_num_rows($query);
if ($check != 0) {
header('Location: error.php?code=2');
exit();
}
// Check if user wants default avatar, if so just add 'em to
// database and get rid of them...
if (!trim($filename)) {
$query = "INSERT INTO members (username,email,password,status,type,quo... VALUES ('$username','$email','$password','user'...
mysql_query($query);
mysql_close($connect);
setcookie("Username", $username, 0);
header('Location: index.php');
}
// Check the filetype isn't fucked...
$filename = strtolower($filename) ;
$exts = split("[/\\.]", $filename) ;
$n = count($exts)-1;
$exts = $exts[$n];
$username2 = $username.".";
$username2 = $username2.$ext;
if(!in_array($exts,$allowed_filetypes...
header('Location: error.php?code=8');
exit();
}
// It's all good so check file size...
$target_path = $target_path . $username2;
if(filesize($_FILES['uploadedfile']['... > $max_filesize){
header('Location: error.php?code=9');
exit();
}
}
?>
Tags: