• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Wavarian

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

8 posts in this topic

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
0

Share this post


Link to post
Share on other sites

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)

0

Share this post


Link to post
Share on other sites

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).

0

Share this post


Link to post
Share on other sites

If Content-Type is text/plain, of a file, you should also add character encoding, like this:

Content-Type: text/html; charset=utf-8

In case you don't supply charset, I gess UTF-8 gets assumed and you have invalid UTF stream in case of 5 bytes and constants like that.

 

You should use the character encoding and some valid bytes in content.

0

Share this post


Link to post
Share on other sites

Sadly, my host won't enable error logging for my "economy" plan. If I had the time, I'd set up a local LAMP stack and test it myself.

 

At one point, I did have the "charset=utf-8" token specified, but ended up stripping everything away until I found the cause of the problem. I was actually trying to upload binary files (application/octet-stream) when I first encountered the bug.

 

In terms of response codes and the like, I receive absolutely nothing back from the server. I send my request, a few seconds go by, and then I get disconnected without any response, after which all other valid requests (from say, a web browser) are disregarded - "The connection was reset".

 

During this time, I can still FTP into the host, and if I use a VPN to change my IP address, I can once again send valid requests to the server and get a response.

 

After around 30 minutes, the server responds to requests again like nothing happened... Until I try sending another 5-byte file.

0

Share this post


Link to post
Share on other sites
Sounds like you found a bug in the host's web stack. Send them a support request.
0

Share this post


Link to post
Share on other sites

If the host is a cheap hosting service not controlled by you, it's very possible the webhost has lame "anti-hacking" measures enabled via custom apatche/php hook and htaccess rules that reject certain input when given in specific order because it matched a malware that used similar input to compromise an unpatched server a long time ago. I've seen that kind of crap before.

If an invalid data is sent, meaning they contradict what is decleread they may pass, but if they become impossible to process for server to establish the hosted active document with input at the level of- this is not three, this is -1=0, kind of way , they close connection instantly without response code, and even prohibit the IP. This is classic, and no browser do those things of coure, you may experience this behavior so many times if you hardcode requests. Totaly standard.

1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0