Need help uploading files

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
amir
Forum Contributor
Posts: 287
Joined: Sat Oct 07, 2006 4:28 pm

Need help uploading files

Post by amir »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I am under a very tight deadline and I'm trying to get my upload_files class working.  I'm trying to test this piece by piece.  Brief synopsis:

The Upload_Files Class will validate the file extension (only certain file extensions can be uploaded), validate the file size (files larger than 25 MB are not allowed), and validate the user (banned users can not upload files).    The code to check the file extension works.  The code to validate the file size appears to be working but this is where I am having my problem.  The code to prevent banned users from uploading is working.  To test the size code, I put in a MAX_FILE_SIZE of 1MB and then tried to upload a file larger than 1MB.  I set the MAX_FILE_SIZE hidden variable in the form and the variable that is passed in my code.  I did not change the php.ini file which is set as the following:

; Maximum allowed size for uploaded files.
upload_max_filesize = 30M

The code to test the file size using 1MB as a MAX_FILE_SIZE worked fine.  Now that I've changed it to be a max of 25MB, it doesn't work and I don't know why.  Here is the pertinent code:

Code: Select all

<?php
$result="";
if (isset($_POST['Submit']))
{
    $result="Form Submitted.";
}
else
{
    $result = "Form not submitted.";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script>
function createstatuswindow(){
   w = window.open('Upload.html','_blank','height=150,width=250');
}
</script>
</head>

<body>
<p>List of projects go here</p>
<form action="test.php" method="post" enctype="multipart/form-data" name="test" id="test">
  <p>
    <input type="hidden" name="MAX_FILE_SIZE" value="26214400" />
    <input name="fname" type="file" id="fname" size="100" maxlength="255" />
  </p>
  <p>
    <input type="submit" name="Submit" value="Submit" />
    <input type="reset" name="Submit2" value="Reset" />
  </p>
</form>
<p><?php echo $result ?></p>
</body>
</html>
The file that I'm trying to load is 11.7MB. When I browse and select the file and click on Submit, I get the message Form not submitted. Any idea why?


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
amir
Forum Contributor
Posts: 287
Joined: Sat Oct 07, 2006 4:28 pm

Post by amir »

I would like to share some more stuff here. I have tested my code from less than 1 MB to 11.5 MB and its working fine but when i tried to upload a file of 11.7 MB, it says
"Form not submitted". I mean if i upload a file of 11.7 MB and more, it says "Form not submitted".
TIA.
User avatar
xpgeek
Forum Contributor
Posts: 146
Joined: Mon May 22, 2006 1:45 am
Location: Kyiv, Ukraine
Contact:

Post by xpgeek »

I think you need to check you php configuration file on post_max_size directive.
By default post_max_size = 10M.
User avatar
w35z0r
Forum Newbie
Posts: 17
Joined: Thu May 18, 2006 7:02 pm

Post by w35z0r »

I have a question relating to making sure only certain file types get uploaded. I scaned your code and I didn't see where it was done at.

Not that I have a suggestion or anything I'm just scanning through trying to learn by observation, when I can across this and wondered how you would do that.

So say I wanted only images (JPEG GIF PNG) to be allowed to be uploaded, how would I do that?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

w35z0r wrote:I have a question relating to making sure only certain file types get uploaded. I scaned your code and I didn't see where it was done at.

Not that I have a suggestion or anything I'm just scanning through trying to learn by observation, when I can across this and wondered how you would do that.

So say I wanted only images (JPEG GIF PNG) to be allowed to be uploaded, how would I do that?
We have many threads on testing and validating file types. Look for them, please.
amir
Forum Contributor
Posts: 287
Joined: Sat Oct 07, 2006 4:28 pm

Post by amir »

Thanks All!

but i dont want to validate file types. I am just asking that when i upload file of 11.5 MB, it works but when i try to upload file of 11.7, it say " form not submitted ".
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

For future reference, the post data doesn't necessarily require the existence of the submit button.

As for your problem, amir, you probably need to adjust some other settings in your configuration. http://php.net/features.file-upload lists the directives that affect upload limits.
amir
Forum Contributor
Posts: 287
Joined: Sat Oct 07, 2006 4:28 pm

Post by amir »

Thanks All.
Great Help.
Post Reply