Jump to content

Recommended Posts

So I'm writing a file upload class that I pretty much completed to my needs, but I'm having a problem with some error reporting.  I'm trying to figure out how to handle POST_MAX_SIZE and report an error to a user if the file exceeds the server limit in the PHP ini.  I have no problems getting the number and converting them to do the math, but I noticed that if the post size exceeds the maximum allowed then I can't even run checks on the data because it as if post never happened. 

 

What I mean is that I check for a form submission and run my class checks

 

if(isset($_POST['submit'])) {
  run my checks and upload my file
}

 

I can't even get inside of my if statement. I've also added the MAX_FILE_SIZE field in my form and hoped to get an error report from $_FILES['field]['errors'], but it doesn't even make it that far.  All of my other checks work and the class works fine, but I need a way to inform the user of this problem which I can't seem to figure out the best way.

Link to comment
https://forums.phpfreaks.com/topic/64769-solved-file-upload-class/
Share on other sites

use the SPY form validation jscript.  It returns the form page and uses predefined variables (could be php echo string) and places them underneath the field, showing the data in teh field.,

 

EX:

 

Upload File: (file upload field)

(submit button)

OUTPUT FROM SpY

Uplaod Files: (file upload field)

Your files: *name* exceeds the maximum size!

File Size: kbyte= *size in kbytes*
File Size: dim=*file dimensions*
octet=*only for exe and p-exe*

mine-type *here*

(submit button)

 

It is good for other things too, but I dont use it for much else.

 

I have attahced SPY source.. SPRY ASSETSSS

 

[attachment deleted by admin]

Check the value of $_FILES['field_name']['error'].  If the file size exceeds the value set for max_upload_size in php.ini it will be equal to 1.  If it is bigger than max_file_size it will equal 2.

 

http://us.php.net/manual/en/features.file-upload.errors.php

Check the value of $_FILES['field_name']['error'].  If the file size exceeds the value set for max_upload_size in php.ini it will be equal to 1.  If it is bigger than max_file_size it will equal 2.

 

http://us.php.net/manual/en/features.file-upload.errors.php

 

Did you read my full post before replying?  It isn't returning anything, it is as if post never happened.

So $_FILES is empty..

what about the $_POST?

 

maybe you could use the isempty($_FILES); them upload time out, the file is too large..

 

just trying to think of some workarounds.. have you got some code i could test to recreate the problem

ok, let me see if I can somehow make this clear what is going on.  Here is my form.

 


<form action="index.php" method="post" enctype="multipart/form-data">
<fieldset>
<input type="hidden" name="MAX_FILE_SIZE" value="<?php $upload->get_max_server_size(); ?>" />
<legend>Upload File</legend>
<label for="file">Choose File</label>
<input type="file" name="file" id="file" />
<input type="submit" name="submit" value="upload file" />
</fieldset>
</form>

 

Here is the short script to handle the form

 


if(isset($_POST['submit'])) {
$upload->set_tmp_file_name($_FILES['file']['tmp_name']);
$upload->set_file_name($_FILES['file']['name']);
$upload->set_file_size($_FILES['file']['size']);
$upload->set_http_error($_FILES['file']['error']);

$upload->upload_file();
}

 

I'm not going to include my class because it is irrelevant. Yes, the object is also created before the post check.  I can return all of the File Errors without problems except for 1.  If the post size is actually larger than what the PHP.ini allows, I can't get into my conditional statement.  I can't see file error which should return

 

 

UPLOAD_ERR_FORM_SIZE

 

    Value: 2; The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.

 

 

If the file attached in the form is larger than the allowed size, then post never seems to send anything, the page just refreshes.  I'm not sure how to account for this and I'm sure I'm not the first to encounter this issue.  Now, to give an example, by default my PHP.ini has a max post size of 8MB and an upload max size of 2MB.  If I try to upload a file that is 3mb, my error reporting works fine, because POST was sent, and I was able to check the $_FILES['name']['error'] field.  If the file is greater than 8MB, which is the post size, I can't do anything with the data because nothing exists to check.

I've searched high and low for the answer and found someone with the exact some problem but there was no answer...

 

http://www.thescripts.com/forum/thread526485.html

 

This is the fix mentioned that I did find on the php site, but I don't want a get variable set

 

If the size of post data is greater than post_max_size, the $_POST and $_FILES superglobals are empty. This can be tracked in various ways, e.g. by passing the $_GET variable to the script processing the data, i.e. <form action="edit.php?processed=1">, and then checking if $_GET['processed'] is set.

 

I can't believe they don't have another way to catch this because it does apparently get reported to a log.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.