Search code examples
http-postmampfwrite

saving image from HTTP_RAW_POST_DATA does not work in MAMP


I'm using the following to upload an image from post data. it works on my server using php version: 5.2.16

When I try running the exact same script on my local server using MAMp and PHP Version 5.2.17 the file is not created.

if (isset($HTTP_RAW_POST_DATA))
{

// Get the data
$imageData=$HTTP_RAW_POST_DATA;
// Remove the headers (data:,) part.  
// A real application should use them according to needs such as to check image type
$filteredData=substr($imageData, strpos($imageData, ",")+1);
// Need to decode before saving since the data we received is already base64 encoded
$unencodedData=base64_decode($filteredData);

echo "unencodedData: ".$unencodedData;
$key = microtime();
$key = md5($key);
// Save file. 
$fp = fopen( '../../../uploadedImages/original/' . $key . '.jpg', 'wb' );
fwrite( $fp, $unencodedData);
fclose( $fp );
}

it looks like the post data does exist if I look at it in firebug. Any ideas why this isn't working in mamp?


Solution

  • Some things to try:

    1. Check to make sure you are getting the raw data when the script is running on MAMP

    2. Check the permissions of the directory it is trying to write to and make sure you have write access to it and apache has write access to it.

    I had issues running some php modules on MAMP so I switched to using versions I installed using MacPorts. It gave me more control of extra extension I wanted to install and I got the latest versions of apache, php, and the php extensions.