JCHASE11
JCHASE11

Reputation: 3941

PHP error on file upload

I keep recieving a PHP error, "Call to undefined function getallheaders() in /home/jbird11/public_html/grids/upload.php on line 8"

The upload script basically takes an image that is dragged into an area, and uploads it. When I drag the image, I get this message.

Here is the first 40 or so lines of the php file:

 <?php

    // Maximum file size
    $maxsize = 1024; //Kb
    // Supporting image file types
    $types = Array('image/png','images/gif','image/jpeg');

    $headers = getallheaders();

    // LOG
    $log = '=== '. @date('Y-m-d H:i:s') . ' ========================================'."\n"
            .'HEADER:'.print_r($headers,1)."\n"
            .'GET:'.print_r($_GET,1)."\n"
            .'POST:'.print_r($_POST,1)."\n"
            .'REQUEST:'.print_r($_REQUEST,1)."\n"
            .'FILES:'.print_r($_FILES,1)."\n";
    $fp = fopen('log.txt','a');
    fwrite($fp, $log);
    fclose($fp);

    header('content-type: plain/text');

    // File size control
    if($headers['X-File-Size'] > ($maxsize *1024)) {
        die("Max file size: $maxsize Kb");
    }

// File type control
if(in_array($headers['X-File-Type'],$types)){
    // Create an unique file name
    $filename = sha1(@date('U').'-'.$headers['X-File-Name']).'.'.$_GET['type'];
    // Uploaded file source
    $source = file_get_contents('php://input');
    // Image resize
    imageresize($source, $filename, $_GET['width'], $_GET['height'], $_GET['crop'], $_GET['quality']);
} else die("Unsupported file type: ".$headers['X-File-Type']);

// File path
$path = str_replace('upload.php','',$_SERVER['SCRIPT_NAME']);
// Image tag
echo '<img src="'.$path.$filename.'" alt="image" />';

Any idea what is causing this error? Permissions perhaps? Permission are set to 755. You can see a working demo of this here: http://pixelcakecreative.com/grids/

Any idea how to fix this? Thanks in advance

Upvotes: 2

Views: 639

Answers (4)

dimaninc
dimaninc

Reputation: 850

you can use this code to be sure you have such a function not depending on server software configuration:

if (!function_exists("getallheaders"))
{
  function getallheaders()
  {
    $headers = "";

    foreach ($_SERVER as $name => $value)
    {
      if (substr($name, 0, 5) == "HTTP_")
      {
        $headers[str_replace(" ", "-", ucwords(strtolower(str_replace("_", " ", substr($name, 5)))))] = $value;
      }
    }

    return $headers;
  }
}

Upvotes: 0

JCHASE11
JCHASE11

Reputation: 3941

from the hosting company: It appears that that function is only supported when PHP is run as an Apache module. Our Shared and Reseller servers run PHP as CGI, and unfortunately this cannot be changed. We apologize for any inconvenience.

If that function is absolutely required for your site, you will need to consider upgrading to a VPS, in which case PHP can be installed however you like.

Upvotes: 0

Maerlyn
Maerlyn

Reputation: 34107

From the docs:

This function is an alias for apache_request_headers(). Please read the apache_request_headers() documentation for more information on how this function works.

If you're not using apache (with php as a module), this function is not available.

Upvotes: 2

radmen
radmen

Reputation: 1624

It's an apache related function. Maybe You don't have needed extensions installed?

Upvotes: 0

Related Questions