Note that there are some explanatory texts on larger screens.

plurals
  1. PODetermine extension type using image stream
    primarykey
    data
    text
    <p>I am developing an API system for my uploading service (in PHP). At the current moment I support the option to send image data as binary data from file_get_contents, fread, etc, or by encoding it with 64 based system. I am attempting to determine the extension type of the image being uploaded to my service from this binary/base64 data. If it is base64 then I decode it and then process it. </p> <p>I have the following at the moment:</p> <pre><code>// We need to figure it out ourselves if ($type === "") { // Let's see if it is a base64 file $base64 = $this-&gt;checkBase64Encoded($file_data); // We got a 64 based file or binary $type = $base64 === TRUE ? "base64" : "binary"; } if ($type == "binary") { $im = imagecreatefromstring($file_data); } </code></pre> <p>I want to see if it is possible to determine the image extension type for saving the file. What do you guys suggest? I read something about using getimagesize()? Although I am not sure about this. Is there no way to get around temporarily saving the file, processing it, and then renaming it?</p> <p>I also planned to use this to test that the image was a valid image before i checked for extension but I wasn't exactly sure how to use the getimagesize() function:</p> <pre><code>try { // Get the width and height from the uploaded image list($width, $height) = getimagesize($file['tmp_name']); // I'm not sure what to put here instead of $file['tmp_name'] } catch (ErrorException $e) { // Ignore read errors } if (empty($width) OR empty($height)) { // Cannot get image size, cannot validate return FALSE; } </code></pre> <p>Please feel free to ask for any clarifications if I was unclear. Thanks so much :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload