Re: [PHP] FUNCTION TO CHECK IMAGE



BBC wrote:
What types of images are these? JPG, PNG, GIF?
Its jpg. Look... I don't know exactly what your point, I'm just asking you about the function to resolve the size of image like the
codes below:
if (file_exists($img_path)){
list($width,$height) = getimagesizes($img_path);
}else{
$width = $ height = $max_size;
}
So is there any other option to replace file_exists();?


Well, if I do remember correctly, then you are uploading a file. If
that's the case, then rather than using file_exists() you should be
using is_uploaded_file. Once you've verified that is_uploaded_file()
returns true, then use move_uploaded_file() to move the file to
someplace on your filesystem. If that returns true, then you should not
have to check file_exists again and just be able to use get getimagesize().

So, a good function for this would probably be:

function getUploadedImageSize($image, $to_path) {
global $max_size;

$width = $height = $max_size;

if (is_uploaded_file($image)) {
if (move_uploaded_file($image, $to_path)) {
list($width,$height) = getimagesize($to_path);
}
}

return array($width, $height);
}

list($width, $height) = getUploadedImageSize($tmp, '/the/final/path');

BTW, I don't know if you did a copy and paste from your code or if you
just typed it in really quickly, but you do have a few syntactical
errors in the code above. First, the image sizing function is
getimagesize - singular, not plural. Second, in your assignment
statement, you have a space where there should not be one:

$width = $ height = $max_size;
^

Just wanted to make sure you knew about that in case it was copied and
pasted.

thank you for your input, it really helps.
========================================================================================
Semarakkan kemerdekaan RI ke 61 th dengan ikut bermain netkuis 17-an di http://netkuis.telkom.net/17an/
Kumpulkan poin sebanyak-banyaknya. Dan siap-siap tunggu rejeki dari sponsor kami.

======================================================================================== .



Relevant Pages

  • Re: Mutiple filename changes
    ... rename .JPG .jpg *.JPG ... If your distro lacks the renameutility, ... Unless you've reformatted it with a Linux filesystem, ... Linux /may/ force the case of files stored on the disk. ...
    (comp.os.linux.setup)
  • Re: Microsoft Update & Zone Alarm 7.0
    ... Perhaps a rebuild of the winsock stack would resolve the issue? ... BTW, Mike Nash is now affiliated with a company that just came out with a ...
    (microsoft.public.windowsxp.general)
  • Need help after system crash
    ... back to a stable state. ... filesystem I received the following: ... fschk.ext3: Unable to resolve 'Label=/opt' ... bash: id: command not found ...
    (Fedora)
  • REPOST: Need help after system crash
    ... back to a stable state. ... filesystem I received the following: ... fschk.ext3: Unable to resolve 'Label=/opt' ... bash: id: command not found ...
    (Fedora)
  • Re: Security Upgrade Cd IGNORANCE
    ... BTW, half of the newsgroups this OP posted to don't resolve ... on the msnews server. ...
    (comp.security.firewalls)