PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, January 15, 2022

[FIXED] saving image from HTTP_RAW_POST_DATA does not work in MAMP

 January 15, 2022     fwrite, http-post, mamp     No comments   

Issue

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.



Answered By - Chris McKnight
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing