Jump to content

PHP Upload Script ends with unknown error.


usapphire

Recommended Posts

Hi again - just like to say thank you for previous help.

 

Just a quick one today, I'm quite sure it's just me doing something completely wrong. After uploading my previous upload/download script and getting it to work (refer to my other topics;

Upload & Download Script and Error in uploading file), it ended up not working completely right.

 

I had someone try to upload a 10 mb file, and it came with an error.. I realized this must have something to do with the max upload allowed, and so, in my .htaccess file, I set it to;

php_value upload_max_filesize 1000M

Just to see if it'll work.

 

Still no luck. After trying to upload a 10 mb file, I think it "times out" within 3-4 minutes. It refreshes the page, where it's suppose to display the "FILE HAS BEEN UPLOADED SUCCESSFULLY", but displays nothing - nor is the file uploaded to the directory, listed on the download list, or even added to the MySQL.

 

Does anyone know what might be the problem?

 

Thank you (I can post the site for those who want to try it out, but it contains 16+ content (it's an upload site for aarinfantasy.com).

Link to comment
Share on other sites

Hi, here is a script that I have used

<?php

$uploadDir = 'C:/AppServ/www/paco/img/';

/* $dir cambia el nombre del directorio a img/ */

$dir = 'img/';

 

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

{

$fileName = $_FILES['userfile']['name'];

$tmpName = $_FILES['userfile']['tmp_name'];

$fileSize = $_FILES['userfile']['size'];

$fileType = $_FILES['userfile']['type'];

 

$filePath = $dir . $fileName;

 

$result = move_uploaded_file($tmpName, $filePath);

if (!$result) {

echo "Error subiendo archivo";

exit;

}

 

include 'includes/config.php';

include 'includes/open.php';

 

 

if(!get_magic_quotes_gpc())

{

$fileName = addslashes($fileName);

$filePath = addslashes($filePath);

}

 

$query = "INSERT INTO upload (name, size, type, path, fecha, comentario, noticia) ".

"VALUES ('$fileName', '$fileSize', '$fileType', '$filePath', '$fecha', '$comentario', '$noticia' )";

 

mysql_query($query) or die('Error, query failed : ' . mysql_error());

 

include 'includes/close.php';

 

echo "<br>Archivo cargado<br>";

 

}

?>

You just need to create a table call upload, and for the $uploadDir, I was having some troubles untill I figure that you have to put all the address from your server /home/interpas/ and so on, it may vary from server to server oh and remember to make your folder 777

hope it works cheers

Link to comment
Share on other sites

Hi.. my upload script works fine - the only thing is that it times out for no reason; it happens in this script too. Uploading files like ~5mb works perfectly, but going for files more than 10mb times out..

 

Thanks for helping, but this didn't fix it :(

Link to comment
Share on other sites

Theres a few things you need mate:

 

1. max post setting

2. max file upload setting

3. max script execution time

4. Apache Limitrequestbody is not too low

 

I have also personally experienced an issue with my IPTABLES script which was preventing large uploads... I had to add:

 

# allow all fragments
-A INPUT -f -j ACCEPT
# allow icmp traffic
-A INPUT -p icmp -j ACCEPT

 

This is explained in the php manual file uploads page.

 

Link to comment
Share on other sites

Theres a few things you need mate:

 

1. max post setting

2. max file upload setting

3. max script execution time

4. Apache Limitrequestbody is not too low

 

I have also personally experienced an issue with my IPTABLES script which was preventing large uploads... I had to add:

 

# allow all fragments
-A INPUT -f -j ACCEPT
# allow icmp traffic
-A INPUT -p icmp -j ACCEPT

 

This is explained in the php manual file uploads page.

 

 

Hello, and thank you for the reply! I don't exactly understand where to put this code, and where do I find the codes / tutorials on how to do the 4 points you listed above? If you want, can I post my full upload script here and have it edited to the way it should work? If this is asking too much, can you point me in the right direction (for tutorials, or something similar)? :D

 

If you can do it for me, I'll repay you by giving you a free webhosting space.. as much as up to 50GB of server space, and whatever bandwidth..

Link to comment
Share on other sites

If you're having problems uploading large files but small files go through fine, here are some things to try:

 

- In the HTML form, make sure you've set MAX_FILE_SIZE to an acceptable value.

- In php.ini, be sure you've set the the upload_max_filesize and post_max_size to be large enough to handle your upload.

- In your httpd.conf (if you're using apache), check that the LimitRequestBody directive isn't set too low (it's optional, so it may not be there at all).

 

If those settings don't work, you can check your firewall configuration. When uploading large files, packets have to be split into fragments of varying size depending on your systems MTU (maximum transmission unit), which is typically 1500 bytes.

 

Because some systems send the packets with the headers last (or the header packet may be received after some of the data packets), firewalls can't filter this traffic based on destination port and address. Many firewalls (including iptables) have to be configured to allow fragments separately from standard traffic. Unfortunately, it's an all-or-nothing thing in these cases, and exploits based on packet fragmentation have been a problem in the past (teardrop, boink, etc.). Note that ICMP may be used to notify the host (your server) of oncoming fragmentation, so you may need to allow ICMP traffic as well.

 

The iptables rules for this are as follows:

# allow all fragments

-A INPUT -f -j ACCEPT

# allow icmp traffic

-A INPUT -p icmp -j ACCEPT

 

On the bright side, this will also fix some issues with ssh and NFS =)

Link to comment
Share on other sites

Hello! Thank you for the very useful reply! There seems to be a problem though.. Where do I locate php.ini? I have a reseller account of a shared hosting, so would that mean I need to contact the server host to change the php.ini? Or should I make a new one in the /etc/ folder?

 

The iptables rules for this are as follows:

# allow all fragments

-A INPUT -f -j ACCEPT

# allow icmp traffic

-A INPUT -p icmp -j ACCEPT

Where do these go? I'm still new to php, so I don't exactly understand where to put these.. :(

Thank you.

Link to comment
Share on other sites

You need to have your host change the php.ini file (if they will) there may be limits for a reason - e.g so users dont use all their resources uploading large files all the time.

 

You will need to get your host to change their IPTables rulesets to implement the iptables bits...

 

Get yourself a dedicated server and learn a bit of linux mate! You have total control then.

Link to comment
Share on other sites

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.