Jump to content

Recommended Posts

Hi to everyone!

 

I'm programming a Class Image to abstracting myself of day-to-day operations like resizing, creting thumbnails, etc.

 

I have two questions:

 

> How can i know if a received parameter is a $_FILES type of var?

> How can i open an image from its path and treat it like a $_FILES var?

 

Thanks a lot.

 

Cheers.

 

Link to comment
https://forums.phpfreaks.com/topic/52955-check-var-type/
Share on other sites

I have two questions:

 

> How can i know if a received parameter is a $_FILES type of var?

> How can i open an image from its path and treat it like a $_FILES var?

 

Huh? Sorry to say, but I really don't understand what you're after. $_FILES is not a data type; it's a predefined global variable. Anything uploaded through a multipart form will be in that array no matter what type it is.

 

If you are looking to check the MIME type of the different files in your $_FILES array using the type key ($_FILES['userfile']['type']).

 

If this is not what you're after, please try to be a little more clear in your description.

Link to comment
https://forums.phpfreaks.com/topic/52955-check-var-type/#findComment-261519
Share on other sites

Hi =)

 

Thanks for answering.

 

The idea behind my class is the following:

 

I want a class that can handle an image and perform some operations with it.

 

I may use it with uploaded images ($_FILES) or with a path to an image.

 

So my constructor could receive two vars...

 

  > $_FILES['whatever']

  > /path/to/whatever/image.jpg

 

And i want to be able to "standarize" both in the constructor. How would you do it?

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/52955-check-var-type/#findComment-261522
Share on other sites

I may use it with uploaded images ($_FILES) or with a path to an image.

So my constructor could receive two vars...

...

And i want to be able to "standarize" both in the constructor. How would you do it?

 

Ah, that makes much more sense. I would personally have the constructor default to one or the other and have an optional second parameter in the constructor that would flag it as the other type. So, you might have something like this:

<?php
class Image {
  public function __construct($file, $uploaded = true) {
    if ($uploaded) {
      // $file is an array from $_FILES, so treat it as such
    } else {
      // $file is a path to an existing file, so treat it as such
    }
  }
}

$img1 = new Image($_FILES['myfile']);
$img2 = new Image('/images/fullsize/default.jpg', false);
?>

 

Hope this helps some.

Link to comment
https://forums.phpfreaks.com/topic/52955-check-var-type/#findComment-261530
Share on other sites

<?php
class Image {
  public function __construct($file, $uploaded = true) {
    if ($uploaded) {
      // $file is an array from $_FILES, so treat it as such
    } else {
      // $file is a path to an existing file, so treat it as such
    }
  }
}

$img1 = new Image($_FILES['myfile']);
$img2 = new Image('/images/fullsize/default.jpg', false);
?>

 

That's just what I was talking about but I was asking pretty much more about WHAT to do inside de constructor =).

 

What it I passed the constructor the PATH to any image. When a file is uploaded I can get it's path with $_FILES['uploadedfile']['tmp_name'] right?

 

So could just call the constructor like one of this

 

$image = new Image("path/to/image.jpg"); 
$image = new Image($_FILES['uploadedfile']['tmp_name']); 

 

and let the constructor get all the information about it's size, width, height, color schema...

 

¡That is my question! How can I get all that information from just a path to an image? I mean, all the information that $_FILES gives us.

 

Thanks a lot mate.

Link to comment
https://forums.phpfreaks.com/topic/52955-check-var-type/#findComment-261646
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.