note 72781 added to function.getimagesize

From: Date: Thu, 01 Feb 2007 13:40:51 +0000
Subject: note 72781 added to function.getimagesize
Groups: php.notes 
Request: Send a blank email to php-notes+get-122474@lists.php.net to get a copy of this message
I was trying to workaround with the problem of getting the mime type of the image from the raw data (the images data is stored in a database and the mime type is not known in advance). Since getimagesize requires a file name, there are some ways to deal with it: 1. call getimagesize with a URL which points to the image - this is too slow. 2. use PHP file i/o wrapper class. 3. use temporary files. The code for #3 could be as follows: function getimagesize_raw($data){ $cwd = getcwd(); #get current working directory $tempfile = tempnam("$cwd/tmp", "temp_image_");#create tempfile and return the path/name (make sure you have created tmp directory under $cwd $temphandle = fopen($tempfile, "w");#open for writing fwrite($temphandle, $data); #write image to tempfile fclose($temphandle); $imagesize = getimagesize($tempfile); #get image params from the tempfile unlink($tempfile); // this removes the tempfile return $imagesize; } ---- Server IP: 69.147.83.197 Probable Submitter: 136.182.158.129 (proxied: 175.37.13.13) ---- Manual Page -- http://www.php.net/manual/en/function.getimagesize.php Edit -- https://master.php.net/note/edit/72781 Del: integrated -- https://master.php.net/note/delete/72781/integrated Del: useless -- https://master.php.net/note/delete/72781/useless Del: bad code -- https://master.php.net/note/delete/72781/bad+code Del: spam -- https://master.php.net/note/delete/72781/spam Del: non-english -- https://master.php.net/note/delete/72781/non-english Del: in docs -- https://master.php.net/note/delete/72781/in+docs Del: other reasons-- https://master.php.net/note/delete/72781 Reject -- https://master.php.net/note/reject/72781 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#122474) next »