flaab Posted May 25, 2007 Share Posted May 25, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/52955-check-var-type/ Share on other sites More sharing options...
obsidian Posted May 25, 2007 Share Posted May 25, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/52955-check-var-type/#findComment-261519 Share on other sites More sharing options...
flaab Posted May 25, 2007 Author Share Posted May 25, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/52955-check-var-type/#findComment-261522 Share on other sites More sharing options...
obsidian Posted May 25, 2007 Share Posted May 25, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/52955-check-var-type/#findComment-261530 Share on other sites More sharing options...
flaab Posted May 25, 2007 Author Share Posted May 25, 2007 <?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. Quote Link to comment https://forums.phpfreaks.com/topic/52955-check-var-type/#findComment-261646 Share on other sites More sharing options...
flaab Posted May 25, 2007 Author Share Posted May 25, 2007 Got it! I'll post my class when finised! http://es.php.net/gd Thx Quote Link to comment https://forums.phpfreaks.com/topic/52955-check-var-type/#findComment-261648 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.