0

Hi I am currently trying to create an upload section for my website, i have looked at multiple websites and examples such as:

W3Schools

I have found out that there are multiple ways that these can go wrong for example mysql injection is each due to them using the $_FILES["file"]["type"]. So I have started to follow this link instead due to it being from php them selves, PHP Documentation

Ok to get to the point I have a problem with the code that I have at the moment I have a simple form that runs the PHP script to check the file upload and then upload if it is correct and come up invalid if it isn't this is partially working, the file uploads but if it is a large file I get a 404 file or directory not found error but if it is a smaller file size it works any ideas.

The HTML form is

<form enctype="multipart/form-data" action="upload_file.php" method="POST">
<!-- MAX_FILE_SIZE must precede the file input field -->
<input type="hidden" name="MAX_FILE_SIZE" value="300000000" />
<!-- Name of input element determines name in $_FILES array -->
Send this file: <input name="userfile" type="file" />
<input type="submit" value="Send File" />

and the PHP file code is

    <?php
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.

$uploaddir = './';//
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    echo "File is valid, and was successfully uploaded.\n";
} else {
    echo "Possible file upload attack!\n";
}

echo 'Here is some more debugging info:';
print_r($_FILES);

print "</pre>";

?>

any ideas would be much appreciated or if anybody knows a better example to use.

user3387522
  • 127
  • 4
  • 19
  • You should check your php.ini file. not sure if you are running the code in WAMP/MAMP/XAMPP or any server? – Bananam00n Mar 06 '14 at 10:17
  • The problem is that your php.ini file has probably set a lower file size than the file you are trying to upload. – Bananam00n Mar 06 '14 at 10:18
  • @Bananam00n I am currently running this on a windows server 2008 R2 and where would the php.ini file be ? – user3387522 Mar 06 '14 at 10:18
  • Check this, it might help you out! http://stackoverflow.com/questions/2184513/php-change-the-maximum-upload-file-size – Bananam00n Mar 06 '14 at 10:19
  • I'm actually out of options, except that it's maybe not the right php file...if you call `phpinfo();` you could see what the path is to your php.ini. if you see the phpinfo, try to fine `configuration file` or some kind. There should be a directory next to it. – Bananam00n Mar 06 '14 at 11:04
  • here's a tutorial to call `phpinfo();` http://www.ostraining.com/blog/coding/phpini-file/ – Bananam00n Mar 06 '14 at 11:05
  • @Bananam00n I used the iis manager on the server and then it shows me the PHP.ini file for the version of PHP that I am currently using.it wouldn't be because of the version of PHP that i am using would it ? or it wouldn't be the file extension that I'm trying to upload. – user3387522 Mar 06 '14 at 11:10

3 Answers3

0

check your upload_max_filesize - 2M in your php.ini file

SagarPPanchal
  • 9,839
  • 6
  • 34
  • 62
0

The maximum file size may be limited in PHP. In php.ini, check the following properties:

upload_max_filesize = 10M
post_max_size = 10M

If it makes no change, you can also try checking memory limit or maximum process time.

KristofMorva
  • 639
  • 1
  • 7
  • 13
  • This did not work what do you mean by checking memory limit and maximum process time ? – user3387522 Mar 06 '14 at 10:33
  • First, did you restart the PHP server after changing the `php.ini`? You must. – KristofMorva Mar 06 '14 at 10:35
  • I have restarted the server and it still gives me the same error and I have also changed the memory_limit within the php.ini – user3387522 Mar 06 '14 at 10:40
  • That's strange. Tried `max_execution_time`? Are your setting high enough? Like `memory_limit = 100M upload_max_filesize = 100M post_max_filesize = 100M`? – KristofMorva Mar 06 '14 at 10:42
  • I have tried max_execution_time and I still get the same results and I have set each one to 100mb because the maximum file size I needed was between 10mb and 100mb – user3387522 Mar 06 '14 at 10:54
  • This is the best answer so far I still can't send the larger file sizes but i think it may be down to my PHP and not the server – user3387522 Mar 06 '14 at 11:52
0

I'm not very familiar with Windows Server, but I googled a bit and found this document:

http://www.webmasterworld.com/microsoft_asp_net/3986574.htm

This says your php.ini file should be located under:

C:\Windows\System32\PHP\php.ini

if you found this file, find and edit the following lines:

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

; Must be greater than or equal to upload_max_filesize
post_max_size = 40M

hope this helps! :-)

Bananam00n
  • 814
  • 9
  • 27