Region: Brazil | Canada | China | France | Germany | Spain | UK | USA | 200 More...




Answer Search Results

PHP Filesize() function...?
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 Fuck - MySQL error!'); mysql_select_db($dbname) or die ('Ah Fuck - 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,quote,joined) VALUES ('$username','$email','$password','user','def','$quote','$date')"; 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']['name']) > $max_filesize){ header('Location: error.php?code=9'); exit(); } } ?>
I keep getting a MySQL error with my php script could someone plz help.?
Warning: fopen(C:\Documents and Settings\david\My Documents\My Pictures\1967FordMustang_large.jpg) [function.fopen]: failed to open stream: No such file or directory in /home2/dhmiller/gamerz-anonymous-www/process.php on line 11 Warning: filesize() [function.filesize]: Stat failed for C:\Documents and Settings\david\My Documents\My Pictures\1967FordMustang_large.jpg (errno=2 - No such file or directory) in /home2/dhmiller/gamerz-anonymous-www/process.php on line 11 Warning: fread(): supplied argument is not a valid stream resource in /home2/dhmiller/gamerz-anonymous-www/process.php on line 11 My Code for the html file is: <html> <body> <div align="center"> <form action="process.php" method="post"> Make: <input type="text" name="Make"><br> Model: <input type="text" name = "Model"><br> Year: <input type="text" name = "Year"><br> Price: <input type="text" name = "Price"><br> Features: <input type="text" name = "Features"><br> Comments: <input type="text" name = "Comments"><br> <input type="text" name="form_description" size="40"> <input type="hidden" name="MAX_FILE_SIZE" value="1000000"> <br>Picture:<br> <input type="file" name="form_data" size="40"> <input type="submit" value="Submit"> </form> </div> </body> </html> My Code For The PHP File is: <?php $Make=$_POST['Make']; $Model=$_POST['Model']; $Year=$_POST['Year']; $Price=$_POST['Price']; $Features=$_POST['Features']; $Comments=$_POST['Comments']; mysql_connect("gamerz-anonymous.com","Test123","Test123") or die(mysql_error()); mysql_select_db("gamerz_anonymous_com_cars") or die(mysql_error()); mysql_query("INSERT INTO `UsedCars` VALUES ('$Make', '$Model', '$Year', '$Price', '$Features', '$Comments')"); $data = addslashes(fread(fopen($form_data, "r"), filesize($form_data))); $result=MYSQL_QUERY("INSERT INTO uploads (description,data,filename,filesize,filetype) ". "VALUES ('$form_description','$data','$form_data_name','$form_data_size','$form_data_type')"); ('$form_description','$data','$form_data_name','$form_data_size','$form_data_type')"); $id= mysql_insert_id(); Print "Your information has been successfully added to the database."; ?> Please Help.
I keep getting a MySQL error with my php script could someone plz help.?
Warning: fopen(C:\Documents and Settings\david\My Documents\My Pictures\1967FordMustang_large.jpg) [function.fopen]: failed to open stream: No such file or directory in /home2/dhmiller/gamerz-anonymous-www/process.php on line 11 Warning: filesize() [function.filesize]: Stat failed for C:\Documents and Settings\david\My Documents\My Pictures\1967FordMustang_large.jpg (errno=2 - No such file or directory) in /home2/dhmiller/gamerz-anonymous-www/process.php on line 11 Warning: fread(): supplied argument is not a valid stream resource in /home2/dhmiller/gamerz-anonymous-www/process.php on line 11 My Code for the html file is: <html> <body> <div align="center"> <form action="process.php" method="post"> Make: <input type="text" name="Make"><br> Model: <input type="text" name = "Model"><br> Year: <input type="text" name = "Year"><br> Price: <input type="text" name = "Price"><br> Features: <input type="text" name = "Features"><br> Comments: <input type="text" name = "Comments"><br> <input type="text" name="form_description" size="40"> <input type="hidden" name="MAX_FILE_SIZE" value="1000000"> <br>Picture:<br> <input type="file" name="form_data" size="40"> <input type="submit" value="Submit"> </form> </div> </body> </html> My Code For The PHP File is: <?php $Make=$_POST['Make']; $Model=$_POST['Model']; $Year=$_POST['Year']; $Price=$_POST['Price']; $Features=$_POST['Features']; $Comments=$_POST['Comments']; mysql_connect("gamerz-anonymous.com","Test123","Test123") or die(mysql_error()); mysql_select_db("gamerz_anonymous_com_cars") or die(mysql_error()); mysql_query("INSERT INTO `UsedCars` VALUES ('$Make', '$Model', '$Year', '$Price', '$Features', '$Comments')"); $data = addslashes(fread(fopen($form_data, "r"), filesize($form_data))); $result=MYSQL_QUERY("INSERT INTO uploads (description,data,filename,filesize,filetype) ". "VALUES ('$form_description','$data','$form_data_name','$form_data_size','$form_data_type')"); ('$form_description','$data','$form_data_name','$form_data_size','$form_data_type')"); $id= mysql_insert_id(); Print "Your information has been successfully added to the database."; ?> Please Help.




Home | Add a Listing | Popular Sites | Top Keywords | Top Rated
What's New | Affiliate Signup | Affiliate Login | Advertiser Signup | Advertiser Login

Thumbnails powered by Thumbshots