By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,188 Members | 844 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,188 IT Pros & Developers. It's quick & easy.

problem while uploading

P: 52
Hi,

I have a page for uploading pictures
I have limited the file uploaded to be jpg ( and other picture types) and size upto 2 MB.

Everything goes well, except when I give files larger than 8 MB (which is the post_max_size) it doesn't show any error, even if the file is of different type other than picture.

It doesn't display any messages, neither success nor failure.

How can I display error messages for those files ?

Thanks
Dec 30 '07 #1
Share this Question
Share on Google+
2 Replies


Markus
Expert 5K+
P: 6,050
Uhm, do you have some if and else statements?

If you'd like to post the relevant code we could help :)
Dec 30 '07 #2

P: 52
Yeah,
the code is
[PHP]<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post" enctype="multipart/form-data">
<br/><br/>
<table width=90% align="center">
<tr>
<td>Upload image:</td>
<td><input type="file" name="image"></td>
</tr>
<tr><td></t><td>
<input type="submit" name="upload" value=Upload>
</td>
</tr>
<tr><td></td><td>
<?php
$link=mysql_connect('localhost','user','user');
mysql_select_db('test');

$typeOK=FALSE;
$sizeOK=FALSE;
$loginid=$_SESSION['loginid'];
$permitted=array('image/jpeg','image/png','image/tiff','image/gif','image/pjpeg');
if (isset($_POST['upload']))
{

if ($_FILES['image']['name'])
{

foreach ($permitted as $type)
{
if ($_FILES['image']['type']==$type)
$typeOK=TRUE;
}

if ($_FILES['image']['size']<1000000 && $_FILES['image']['size']>0)
$sizeOK=TRUE;

if ($sizeOK && $typeOK)
{
define('UPLOAD_DIR', '/var/www/html/uploads/');
//remove spaces from uploaded file
$file=str_replace(' ','_',$_FILES['image']['name']);
$completepath=UPLOAD_DIR."$loginid/$file";

$date=date('Y-m-d');

$query="insert into pictures values('$completepath','$loginid','','$date')";
$result=mysql_query($query);
//if insert into database is successful
if ($result){

//make directory named after the name of user loginid if it doesn't already exist
if (!is_dir(UPLOAD_DIR.$loginid)) mkdir(UPLOAD_DIR.$loginid);
//move the uploaded file
if (move_uploaded_file($_FILES['image']['tmp_name'], $completepath))
print("<br/><font color=green>Uploaded file successfully to database");
else print ("<br/> Couldn't upload to server");
}
}
else { print ("<br/><font color=red>Upload Failed <br/>"); if (!$sizeOK) print("Size of file is out of the range"); else if (!$typeOK) print("This file type is not supported"); }
}
else print("<font color=red>No file selected");
}
?>
[/PHP]
Dec 30 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.