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

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 ?

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

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
the code is
[PHP]<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post" enctype="multipart/form-data">
<table width=90% align="center">
<td>Upload image:</td>
<td><input type="file" name="image"></td>
<input type="submit" name="upload" value=Upload>

if (isset($_POST['upload']))

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

foreach ($permitted as $type)
if ($_FILES['image']['type']==$type)

if ($_FILES['image']['size']<1000000 && $_FILES['image']['size']>0)

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


$query="insert into pictures values('$completepath','$loginid','','$date')";
//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");
Dec 30 '07 #3

Post your reply

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