...

View Full Version : php file upload problem. need help



Thenewphp
09-19-2011, 01:26 PM
It is supposed that when i upload a file greater than 100kb. i should get an error.. but the file still uploads..

Here is the code:


<?php
if(isset($_FILES['file'])){
$name = $_FILES['file']['name'];
$type = $_FILES['file']['type'];
$size = $_FILES['file']['size'];
$max_size = 100000;
$extension = strtolower(substr($name, strpos($name, '.') + 1));






$tmp_name = $_FILES['file']['tmp_name'];

if (isset($name)) {
if(!empty($name)) {

if ($extension=='jpg'||$extension=='jpeg'&&$type=='image/jpeg'&&$size<=$max_size) {
$location = 'uploads/';

if (move_uploaded_file($tmp_name, $location.$name)) {
echo 'Uploaded!';

}

} else {
echo 'File must be jpg or jpeg and 1mb';
}


} else {
echo 'Please choose a file';
}
}
}

?>
<form action="page2.php" method="POST" enctype="multipart/form-data">
<input type="file" name="file"><br /><br />
<input type="submit" value="Submit">
</form>

Wanna
09-19-2011, 01:38 PM
Try to echo the file size before checking it.
So can you see if the file you uploaded really is 100kb

tangoforce
09-19-2011, 01:41 PM
Please would you start using [php] tags? - See the link in my signature.

Wanna
09-19-2011, 01:47 PM
Please would you start using [php] tags? - See the link in my signature.

Yes indeed, This is very irritating to read for us.

Thenewphp
09-19-2011, 06:05 PM
I already echo the file size it is over 100kb it is 185kb its still not working

Thenewphp
09-19-2011, 07:44 PM
i've a solution to it found the solution... its ok now

Wanna
09-20-2011, 07:58 AM
Could you please paste teh solution here so we also know what was wrong.

tomharto
09-20-2011, 08:52 AM
From a look i guess the problem was this if


if ($extension=='jpg'||$extension=='jpeg'&&$type=='image/jpeg'&&$size<=$max_size)

I guess he changed it to something like


if (($extension=='jpg'||$extension=='jpeg')&&$type=='image/jpeg'&&$size<=$max_size)

Wanna
09-20-2011, 09:29 AM
I don't think that.
That check: if ext = jpg OR jpeg AND ... AND ...

So i don't think that what you say is the solution

Thenewphp
09-21-2011, 08:46 PM
I make it like this: if (isset($name)) {
if(!empty($name)&&$extension=='jpg'||$extension=='jpeg'&&$type=='image/jpeg') {

if ($size<=$max_size) {
$location = 'uploads/';

if (move_uploaded_file($tmp_name, $location.$name)) {
echo 'Uploaded!';

}

} else {
echo 'File must be jpg or jpeg and 1mb';
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum