|
|||||||
New to SitePoint Forums? Register here for free!
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
SitePoint Guru
![]() ![]() ![]() ![]() ![]() Join Date: Jul 2003
Location: True North
Posts: 625
|
Uploading Images In ColdFusion
I would like a little help from you fine folks here
I know how to upload images, rename them and place them in directorys. What I would like to is befor I upload them Check thier extension, file size and dimernsions in that order of importance. Is this possible? I have been searching but with no luck, Thanks |
|
|
|
|
|
#2 |
|
minister of propaganda
![]() Join Date: Feb 2004
Location: Midsouth
Posts: 1,400
|
youre talking about mime types, i dont use them much so i cant tell you what you need off the top of my head. i think davidjmedlock has helped me with something like this before, hopefully he will stop by here soon.
if i can come up with that previous post ill let you know, i cant seem to find it so far though. |
|
|
|
|
|
#3 |
|
minister of propaganda
![]() Join Date: Feb 2004
Location: Midsouth
Posts: 1,400
|
|
|
|
|
|
|
#4 |
|
SitePoint Wizard
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jul 1999
Location: Powder Springs GA (Atlanta)
Posts: 1,344
|
sounds like you are dealing with images (dimension?) have you looked into image Magik? there's a cool CF tag at http://www.alagad.com/index.cfm/name-mtinfo and it's free!
|
|
|
|
|
|
#5 |
|
SitePoint Guru
![]() ![]() ![]() ![]() ![]() Join Date: Jul 2003
Location: True North
Posts: 625
|
Thanks buddy, I dont want to change the file, just want to restrict them from uploading anything but .jpg.
I think I am going to try and use some error handling using the file .extensions. Later |
|
|
|
|
|
#6 | |
|
SitePoint Wizard
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Dec 2002
Location: Nashville, TN USA
Posts: 2,039
|
Quote:
![]() Here's an article on File Uploads: http://www.kodefusion.com/article/in...d&ArticleID=13 To check for image MIME types, you want to use the "accept" attribute of CFFILE. You would enter a comma delimited list of MIME types you're willing to allow users to upload and then ColdFusion would automatically accept or reject it based on the file type. For images you might specify "image/jpeg,image/pjpeg,image/gif,image/png,image/bmp". You might be able to specify "image/*", but I'm not 100% sure. Also, look at my latest article on SitePoint about using HTTP with ColdFusion. There's some code in there for a simple Image server that you might find useful. |
|
|
|
|
|
|
#7 |
|
SitePoint Guru
![]() ![]() ![]() ![]() ![]() Join Date: Jul 2003
Location: True North
Posts: 625
|
Well What I did is download the imageinfo custom tag from Macromedia (it is free) to give the information of file type, file size and dimensions.
I know File.ServerFile and other functions would have got me the extension and size fo the file but no dimensions so I am using this. My logic is 2 upload to a temp directory, check the the file to see if it fits my rule for size, dimensions and ext. If it does, rename it and upload it to my directory, if it does not, store the value of size, dimensions and ext in a variable, delete the temp file and display the error to the user. Does this sound like the right logic to use? Thanks Mike |
|
|
|
|
|
#8 |
|
SitePoint Wizard
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Oct 2000
Location: Nashvegas Baby!
Posts: 7,991
|
mdumka...
Care to share that custom tag? |
|
|
|
|
|
#9 | |
|
SitePoint Wizard
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Dec 2002
Location: Nashville, TN USA
Posts: 2,039
|
Quote:
|
|
|
|
|
|
|
#10 |
|
SitePoint Guru
![]() ![]() ![]() ![]() ![]() Join Date: Jul 2003
Location: True North
Posts: 625
|
Thanks guys, will up the tag on monday!
Later |
|
|
|
|
|
#11 |
|
SitePoint Guru
![]() ![]() ![]() ![]() ![]() Join Date: Jul 2003
Location: True North
Posts: 625
|
Here is the ImageInfo custom tag.
Later |
|
|
|
|
|
#12 |
|
SitePoint Guru
![]() ![]() ![]() ![]() ![]() Join Date: Jul 2003
Location: True North
Posts: 625
|
why is the upload not showing?
If I go to edit my post it shows it uploaded but not in my post. Help? |
|
|
|
|
|
#13 |
|
SitePoint Wizard
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Oct 2000
Location: Nashvegas Baby!
Posts: 7,991
|
It hasn't been approved yet. An admin has to look it over before it gets made public.
|
|
|
|
|
|
#14 | |
|
SitePoint Guru
![]() ![]() ![]() ![]() ![]() Join Date: Jul 2003
Location: True North
Posts: 625
|
Quote:
Later |
|
|
|
|
|
|
#15 |
|
SitePoint Wizard
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Oct 2000
Location: Nashvegas Baby!
Posts: 7,991
|
Great...can't wait to get it.
|
|
|
|
|
|
#16 |
|
SitePoint Member
Join Date: Apr 2004
Location: Raleigh, NC
Posts: 15
|
there may be a better way but here's how i do it
i actually upload the file, check its extension and delete it if its not an acceptable image file(gif and .jpg) <cfif #cffile.ClientFileExt# EQ 'gif' OR #cffile.ClientFileExt# EQ 'jpg' OR #cffile.ClientFileExt# EQ 'pjpeg' OR #cffile.ClientFileExt# EQ 'jpeg' OR #cffile.ClientFileExt# EQ 'pjpg'> i havn't had any speed issues with this process yet. if anybody has a better idea, i could use this tip too |
|
|
|
|
|
#17 |
|
SitePoint Guru
![]() ![]() ![]() ![]() ![]() Join Date: Jul 2003
Location: True North
Posts: 625
|
but how do you check dimensions?
I ask this becuase sometimes I have to ensure my users do not upload the wrong size images. |
|
|
|
|
|
#18 |
|
SitePoint Wizard
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Oct 2000
Location: Nashvegas Baby!
Posts: 7,991
|
lostfox...
Why take the time to make that check when you can simply prevent users from uploading a file type that you don't want to begin with? Like so: PHP Code:
|
|
|
|
|
|
#19 |
|
SitePoint Member
Join Date: Apr 2004
Location: Raleigh, NC
Posts: 15
|
PHP:
<cffile action="upload" fileField="uploadbanner" destination="#uploadPath#" nameConflict="MakeUnique" accept="image/gif,image/jpeg,image/pjpeg"> i do it that my way because if they try to upload file with an unacceptable extension, the user gets a coldfusion error. with the way i do it, i can print out a "hey you tried to upload an unacceptable file" message to them along with instructions of what to do next. i don't know how common this is, but i try to keep the user from getting the coldfusion errors |
|
|
|
|
|
#20 | |
|
SitePoint Member
Join Date: Apr 2004
Location: Glasgow, Scotland, UK
Posts: 2
|
Quote:
|
|
|
|
|
|
|
#21 | |
|
minister of propaganda
![]() Join Date: Feb 2004
Location: Midsouth
Posts: 1,400
|
Quote:
|
|
|
|
|
|
|
#22 |
|
SitePoint Wizard
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Oct 2000
Location: Nashvegas Baby!
Posts: 7,991
|
Good point Lostfox...thanks for clarifying.
|
|
|
|
|
|
#23 |
|
SitePoint Member
Join Date: Apr 2004
Location: Raleigh, NC
Posts: 15
|
The next time i have the chance, i will give the cftry and cfcatch a go. that is the first that i've heard of it. when i started the project in which used the above code, i did a quick look into a try/catch type of functions but quickly gave up and decided i could write the code to upload and delete it just as easily.
thanks for the tip. |
|
|
|
|
|
#24 | |
|
minister of propaganda
![]() Join Date: Feb 2004
Location: Midsouth
Posts: 1,400
|
Quote:
|
|
|
|
|
![]() |
| Bookmarks |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
|
All times are GMT -7. The time now is 07:31.










Linear Mode
