Jump to content

  • Log In with Google      Sign In   
  • Create Account

Anyone Tried Uploading A 5-Byte File To Php Before?

  • You cannot reply to this topic
2 replies to this topic

#1 Wavarian   Members   -  Reputation: 828

Like
0Likes
Like

Posted Yesterday, 06:02 AM

Lately I've been tinkering around with uploading files to a PHP server via winsock, and today encountered an issue where I'd receive no response from the server, and for the next 30 minutes or so, all attempts to access the server via a browser would produce the dreaded "The connection was reset" error. Investigating further, I was actually able to connect to the server, but immediately upon sending a request, the server would close the connection.

 

The cause? You tell me. Server was running PHP 5.2. Mind you, "1", "12", "123", and "1234" all work as well.

 

This works:

REQUEST>

POST /bug/index.php HTTP/1.1
Host: sample.com
Connection: close
Content-Type: multipart/form-data; boundary=HTTPClientBoundary
Content-Length: 144

--HTTPClientBoundary
Content-Disposition: form-data; name="moo"; filename="cow.txt"
Content-Type: text/plain

123456
--HTTPClientBoundary-- 

RESPONSE>

SAVED: cow.txt

This doesn't:

REQUEST>

POST /bug/index.php HTTP/1.1
Host: sample.com
Connection: close
Content-Type: multipart/form-data; boundary=HTTPClientBoundary
Content-Length: 143

--HTTPClientBoundary
Content-Disposition: form-data; name="moo"; filename="cow.txt"
Content-Type: text/plain

12345
--HTTPClientBoundary--

RESPONSE>

<disconnect>

index.php

<?php

if(!empty($_FILES))
{
	$upload_dir = pathinfo($_SERVER['SCRIPT_FILENAME'], PATHINFO_DIRNAME) . '/';

	foreach($_FILES as $entry)
	{
		if(is_uploaded_file($entry['tmp_name']) && ($entry['error'] === UPLOAD_ERR_OK))
		{
			if(move_uploaded_file($entry['tmp_name'], $upload_dir . $entry['name']))
			{
				echo 'SAVED: ' . $entry['name'];
			}
			else
			{
				unlink($entry['tmp_name']);
			}
		}
	}
}

Edited by Wavarian, Yesterday, 06:06 AM.


#2 Matias Goldberg   Crossbones+   -  Reputation: 8289

Like
0Likes
Like

Posted Yesterday, 12:43 PM

File uploading must be enabled via php.ini (keywords are 'file_uploads = On'; 'upload_max_filesize'; 'memory_limit' and 'post_max_size')

 

Some of them affect uploads directly, some of the keywords affect them indirectly (i.e. large upload_max_filesize is useless if you run out of memory)



#3 Wavarian   Members   -  Reputation: 828

Like
0Likes
Like

Posted Yesterday, 05:56 PM

This issue only occurs when you try to upload a 5-byte file though; it works for all other file sizes (up to max filesize).







PARTNERS