tags:

views:

37

answers:

2
<?php
if($_POST['uae']){
 move_uploaded_file($_FILES["file"]["tmp_name"], FS_DOC_ROOT . 'uploads/' . urlencode($_FILES['file']["name"]));
 mail("email@address","Uploaded File for you",$_POST['message']."\n\nTo view the file please follow the following link: ".HTTP_SERVER."uploads/".urlencode($_FILES['file']['name']).".","FROM: DONOTREPLY <[email protected]>");
 echo "<div style='background: green;color: #ffffff;padding: 5px;'>All sent... send another one below.</div>";
}
?>

<form method="post" action="uploadandemail.html" enctype="multipart/form-data">

 <table>
     <tr>
         <td>Choose a file to upload:</td>
            <td><input type="file" name="file" /></td>
        </tr>
        <tr>
         <td valign="top">Message:</td>
            <td><textarea name="message" cols="40" rows="40" style="height: 150px;">I have uploaded a file for you.</textarea><br />This will be superceeded with "To view the file please follow the following link: http://linktoyour.new/file.doc".&lt;/td&gt;
        </tr>
        <tr>
         <td></td>
            <td><input type="submit" name="uae" value="Upload and Email" /></td>
        </tr>
    </table>

</form>

It doesn't work - it will quite happily upload a small image or a PDF but it don't upload an mp4 or an mpeg. It doesn't even try it, the page just refreshes straight away.

Any ideas? php.ini is set to 100M max upload.

This is my php5.ini file:

error_reporting  =  E_ALL
upload_max_filesize = 100M

Thanks

+1  A: 

There must be a default in MAX_FILE_SIZE that is too low for the big file. While MAX_FILE_SIZE can be fooled, as the php.net site points out, it's a convenience so a user doesn't wait out a long upload only to find the file is too big because of a php.ini setting

From: http://www.php.net/manual/en/features.file-upload.post-method.php

The MAX_FILE_SIZE hidden field (measured in bytes) must precede the file input field, and its value is the maximum filesize accepted by PHP. This form element should always be used as it saves users the trouble of waiting for a big file being transferred only to find that it was too large and the transfer failed. Keep in mind: fooling this setting on the browser side is quite easy, so never rely on files with a greater size being blocked by this feature. It is merely a convenience feature for users on the client side of the application. The PHP settings (on the server side) for maximum-size, however, cannot be fooled.

Hans
ok added `<input type="hidden" value="100000" name="MAX_FILE_SIZE" />` before my file upload, but still not working! :(
Thomas Clayson
That's about 100k, so you might add a couple of zeros so it's a larger value than you file. Also, add it as the first line after the opening form call. It needs to precede the input type="file" line
Hans
ah... that would be correct. :p I got confused with the zeros :p
Thomas Clayson
this seems to work now, thanks. :)
Thomas Clayson
+1  A: 

my ini settings

memory_limit: 1G
post_max_size: 400M
upload_max_filesize: 100M

max_execution_time: 450

(test) File-size: ~31MB

$_FILES dump

Array
(
    [userfile] => Array
        (
            [name] => Adium.app.zip
            [type] => application/zip
            [tmp_name] => /private/tmp/phpuuG0VK
            [error] => 0
            [size] => 33300224
        )

)
maggie
that was ~ the same as mine. :) it was the lack of 0s in my MAX_FILE_SIZE hidden field. Thank you very much for your help. :)
Thomas Clayson