Welcome! Log In Create A New Profile

Advanced

apache_request_headers replicement

Posted by hmert 
apache_request_headers replicement
August 08, 2010 06:18AM
Hello,
I'm developing a xhr uploading script by using http://github.com/valums/file-uploader
But nginx has no apache_request_headers function, and find from php.net an replicement.
[code]
function _apache_request_headers() {
foreach($_SERVER as $key=>$value) {
if (substr($key,0,5)=="HTTP_") {
$key=str_replace(" ","-",ucwords(strtolower(str_replace("_"," ",substr($key,5)))));
$out[$key]=$value;
}
}
return $out;
}
[/code]
my problem is that upload script has following function that needs a content-lenght param which nginx does not have
[code]
function getSize(){
$headers = [b]apache_request_headers[/b]();
return (int)[b]$headers['Content-Length'][/b];
}
[/code]

so I add an extra param to my site config

[code]
fastcgi_param CONTENT-LENGTH $content_length;
[/code]


this parameter is needed for how much bytes uploaded to the server (maybe I get it wrong)

how can I fix this problem? Thanks for all (sorry for my poor english)
Re: apache_request_headers replicement
August 10, 2010 01:20PM
I make an awfull mistake :) CONTENT-LENGTH has no HTTP_ prefix so my php is just stay it same.
here is my change http://gist.github.com/505962
[code]
if (substr($key,0,5)=="HTTP_") {
$key=str_replace(" ","-",ucwords(strtolower(str_replace("_"," ",substr($key,5)))));
$out[$key]=$value;
}else{
$out[$key]=$value;
}
[/code]

it's solved. :)
Re: apache_request_headers replicement
March 23, 2012 11:47AM
sorry for digging...

from php changelog:

5.4.0 This function became available under FastCGI. Previously, it was supported only when PHP was installed as an Apache module.

But still getallheaders() and apache_request_headers() is undefined functions in nginx+php-fpm, why?
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 163
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready