Welcome to WebmasterWorld Guest from 35.173.47.43

Forum Moderators: ocean10000

Message Too Old, No Replies

Classic ASP "PHP $ FILE" alternative

Need ASP to check Mime, Width and Height of an Image.

     
10:17 am on Apr 24, 2010 (gmt 0)

New User

5+ Year Member

joined:Mar 17, 2010
posts: 10
votes: 0


Basically what I have is a form with an input file.
It should check the file mime against an allowed types array and if it's an image then get the width and height of that image.
(There are only jpeg, png, gif and bmp in the array so far.)
I have no need to save it anywhere but can do so temporarily if necessary.

Anyone have any idea's on how to do this in Classic ASP/VBSCRIPT? Or if there are any complete scripts like that already...

Anyhow, here's the PHP script if that helps:

$mime = array (
'image/jpeg',
'image/png',
'image/gif',
'image/x-ms-bmp'
);

if ( isset ( $_FILES['image'] ) ) {
foreach ( $mime as $m ) {
if ( $_FILES['image']['type'] == $m ) {
$ok = true;
}
}
if ( $ok === true ) {
$image = getimagesize ( $_FILES['image']['tmp_name'] );
list ( $width, $height ) = explode ( ' ', $image[3] );
$width = substr ( $width, 7, -1 );
$height = substr ( $height, 8, -1 );
} else {
$error = 'Invalid Image Format: ' . $_FILES['image']['type'];
}
}
8:39 pm on Apr 24, 2010 (gmt 0)

Senior Member from GB 

WebmasterWorld Senior Member dstiles is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:May 14, 2008
posts: 3272
votes: 19


I've been using BitmapLibrary for several years (my copy came in bitmapsize.zip). You may have trouble tracking it down as there is another BitmapLibrary that's for fonts.

BitmapLibrary is a DLL that needs to be installed on the server. If you can't do that then you need to find/create a script that looks at the header of the image file and extracts the information. The header info varies quite a bit depending on jpg/gif/etc and on sub-type of each.
9:06 pm on Apr 24, 2010 (gmt 0)

New User

5+ Year Member

joined:Mar 17, 2010
posts: 10
votes: 0


Thanks for the reply but dll's aren't really what I was looking for as the complete script should work on as many servers as possible. Will check if I can find it though and unless another solution presents itself it might be the only way. As for reading the header info, that's just out of my league as I only started scripting ASP/VBSCRIPT a few days ago. Perhaps I should scrap the ASP version altogether and go with some .net or another. Was planning on a .net version as well after this one. Not that I know anything about .net either.

Any other ideas or any help will be appreciated. Also any good references sources for Classic ASP and/or VBSCRIPT would be nice. I've been using w3schools for now and what I can find on a quick google search but google always gets me asp.net instead...
10:19 pm on Apr 25, 2010 (gmt 0)

Senior Member from GB 

WebmasterWorld Senior Member dstiles is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:May 14, 2008
posts: 3272
votes: 19


Sorry, can't help beyond that.

If you get only asp net from google and you're not aware of google's personalisation, check out the google forum on WebmasterWorld.
11:16 am on Apr 26, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 12, 2002
posts:1482
votes: 0


The closest you can get without using any 3rd party tools is the VBScript function "LoadPicture("filename")". There isn't a ton of documentation on it, and I've only ever really used it to get the width/height of the image.

If you're just looking to check file extensions, you can pretty easily just use some string based tools like InStr to find a period and see what comes after it. Or you can use Split to turn the string into an array.

This is obviously pretty rudimentary, but should get in the right direction.
12:35 pm on Apr 26, 2010 (gmt 0)

New User

5+ Year Member

joined:Mar 17, 2010
posts:10
votes: 0


I stumbled upon LoadPicture yesterday, was looking into it a bit. It seems to be an easy way to get width and height, though I need to save the file on disk then.
I found a way to get the mime/content-type, size and file-name of files with pure asp and without the need to save to disk from a file upload script. I modified it a little to remove a lot of unnecessary features but it does the job so far. Was going to look into getting width and height somehow, but using LoadPicture might be quicker...
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members