Search code examples
phpfiledrop.js

PHP HTTP_X_FILE_NAME removed, what alternatives do I have


Good day,

I use filedrop to upload images in my application. Recently I moved to PHP 7.1 on my development location and I found out that HTTP_X_FILE_NAME has been removed.

Searching the web I found out that this key has been removed as "unnecessary"

However I do not know what to substitute it with?

I used to fetch the uploaded file with the following code :

$name = urldecode($_SERVER['HTTP_X_FILE_NAME']);
$data = file_get_contents("php://input");

Solution

  • $_SERVER['HTTP_X_FILE_NAME'] is not something standard in any version of PHP, but it is available when an 'X-file-name' request header was set. For example, you can see filedrop.js setting this request header here: https://github.com/ProgerXP/FileDrop/blob/33f85ce84a1df890ab5d9dcf6d105c457b2f18b0/filedrop.js#L2033.

    Please see what headers are available in the $_SERVER super-global (e.g. by doing a var_dump($_SERVER)). It may happen that 'HTTP_X_FILE_NAME' got prefixed with a REDIRECT_ prefix because of your current server configuration and then you should use $_SERVER['REDIRECT_HTTP_X_FILE_NAME'].