Advertisement

08.07.2008 at 06:08AM PDT, ID: 23629096
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.0

get filename from base64 decoded image

Asked by KoenVDS in PHP for Windows

Tags: ,

I am currently working on a couple of functions that process a http posted XML document. In that document, there is a tag "image", which contains a base64 encoded string, holding the image information. i have come to the point where i can decode the base64 string, and display the image on screen.

next i want to build in some security checks, i.e. making sure the base64 string is indeed an image file. Therefor i have written a small function that checks for an imagetype, which returns false when no valid type was found. Because of security reasons, i would prefer to keep the base64 DECODED variable in memory, or at most in a tmpfile();  (temporary file) and not to store it on harddisk before manipulating it further. The final goal of the php routine is to process the xml and maniuplate the sent images into different sizes (thumbnail, medium, large, ...) ,store those to a harddrive location and insert the link (filename) into a database table.

The problem i am currently having is applying the checks for imagetype, because it looks up the fileproperties by use of a filename, which i dont have. i am also anticipating this will cause further problems when trying to resize the image, because it does not exist physically on a harddisk location, only in memory

Is it possible to extract a filename from the base64 decoded image, so i dont have to store it to a location first, and will it be possible to further manipulate the 'image' ?

The following code snippet is what i have at this point. I have to admit i'm only programming in PHP for 2 days now, but i've been programming for 4 years so far, so please don't spare me some technical details.

many thanks in advance for a quick reply.Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
function processImages($imageItems)
{ // Verifies base64 imagecode and stores in database
	global $authenticationInfo;
	foreach($imageItems->getElementsByTagName('image') as $imageItem) // go through imageItems
	{
		writeToLog(" -- PROCESSING IMAGE INITIATED -- User: (UID ".$authenticationInfo->getElementsByTagName('user')->item(0)->getAttribute('id').")");
		if(!base64_decode($imageItem->nodeValue)){
			writeToLog(" --- PROCESSING IMAGE FAILED -- User: (UID ".$authenticationInfo->getElementsByTagName('user')->item(0)->getAttribute('id').") - Invalid base64 characterset found!");
		}else{
			$decodedImage = base64_decode($imageItem->nodeValue);
			$decodedImageType = $imageItem->getAttribute("type");
			$tmpFile = tmpfile();
			
			file_put_contents('testFile.jpg', $decodedImage);
			echo $tmpFile;
			
			if(false) //!exif_imagetype($decodedImage)
				writeToLog(" --- PROCESSING IMAGE FAILED -- USER: (UID ".$authenticationInfo->getElementsByTagName('user')->item(0)->getAttribute('id').") - Base64 characterset is not a valid image file!");
			else{
				// store image to disk
				//echo "its a done deal, sis'";
			}
		}
		writeToLog(" -- PROCESSING IMAGE TERMINATED -- User: (UID ".$authenticationInfo->getElementsByTagName('user')->item(0)->getAttribute('id').")");
	}
	unset($imageItem); // clear memory resources
}
function exif_imagetype ( $filename ) {
	if ( ( list($width, $height, $type, $attr) = getimagesize( $filename ) ) !== false ) {
		return $type;
	}
	return false;
}
 
Loading Advertisement...
 
[+][-]08.07.2008 at 07:11AM PDT, ID: 22181095

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]08.08.2008 at 01:29AM PDT, ID: 22188248

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: PHP for Windows
Tags: php, firefox, internet explorer
Sign Up Now!
Solution Provided By: KoenVDS
Participating Experts: 1
Solution Grade: A
 
 
[+][-]08.08.2008 at 02:34AM PDT, ID: 22188488

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-42 / EE_QW_2_20070628