Jump to content

FileUpload with only images & file extension


mierlp
 Share

Recommended Posts

Hi,

 

Within my application i registrate employees, every employee has a unique

nummer (something like 05432467). The employee needs to upload a copy (scan/image)

from his ID card.

 

The FileUpload is not the problem but i would like to upload only images so the

employ may only see/filter image files.

 

Because a scan can have any name i also would like to change the name when

i upload it. So the images gets the name of the employee nummber, something

like 05432467.jpg. To do this i need to extract thee extension because a

image can be a .jpg, gif, tif etc.

 

- How to create a filter when the user selects a file for thee upload

- How to retrieve the extension from the uploaded file

 

Regards Peter

Link to comment
Share on other sites

This may be useful ?

Once you have the file on the server you can fairly easily check if the file header looks appropriate (PNG/BMP/JPG).

e.g

 

function IsJpegFile(const FileName: string): Boolean;
const
 RightBuf: array[0..3] of Byte = ($FF, $D8, $FF, $D9);
var
 Buf: array[0..3] of Byte;
begin
 FillChar(Buf, 4, 0);
 with TFileStream.Create(FileName, 0) do
 begin
   Position := 0;
   ReadBuffer(Buf[0], 2);
   Position := Size - 2;
   ReadBuffer(Buf[2], 2);
   Free;
 end;
 Result := CompareMem(@RightBuf[0], @Buf[0], 4);
end;

function IsBmpFile(const FileName: string): Boolean;
const
 RightBuf: array[0..1] of Byte = ($42, $4D);
var
 Buf: array[0..1] of Byte;
begin
 FillChar(Buf, 2, 0);
 with TFileStream.Create(FileName, 0) do
 begin
   Position := 0;
   ReadBuffer(Buf[0], 2);
   Free;
 end;
 Result := CompareMem(@RightBuf[0], @Buf[0], 2);
end;

function IsPngFile(const FileName: string): Boolean;
const
 RightBuf: array[0..7] of Byte = ($89, $50 ,$4e, $47, $0d, $0a, $1a ,$0a);
var
 Buf: array[0..7] of Byte;
begin
 FillChar(Buf, 8, 0);
 with TFileStream.Create(FileName, 0) do
 begin
   Position := 0;
   ReadBuffer(Buf[0], 7);
   Free;
 end;
 Result := CompareMem(@RightBuf[0], @Buf[0], 7);
end;

 

 

[with a little help from here http://www.hidelphi.com/201004/check-a-picture-file-type-jpeg-or-bitmap-using-tfilestream/ and here http://www.fileformat.info/format/png/corion.htm]

Link to comment
Share on other sites

I'm currently doing something a bit similar and have been looking at some automatic face detection or recognition as an attempt to give some probability that the uploaded file does actually contain a useful image.

The larger commercial SDKs are a bit expensive.

These guys might be useful http://face-detection-recognition.com/ - anyone know how to write an interface to the C++ dll they have ?

 

 

Cheers

Link to comment
Share on other sites

  • 11 months later...

As far as I know it is not possible.

 

 

 

 

See our Upload demo.

 

there is a "filter"-property in the UniGUI file upload components, but it does seem to have no effect on filtering file extensions for uploading. Are there any news how to set an  extension filter with the standard UniGUI file upload component?

 

Best Regards

Link to comment
Share on other sites

hear exist examle how do dragdrop html5. I am done so And where in javascrip code handled event draon dragstart and drop

 

On drop you can check fileextension and exist javascrip library understatndig kind of file - peg img gif and so on  client browser side before sending to server.

 

C-dll have interfece using image file/string and  coordinates  To use need export dll inteface by delphi dll export tools Will be created pascal wrapper such as MSoffise wrappers. Dll reaklli recognize faces but in additional need html5 webcam integration study,

Link to comment
Share on other sites

I have two frame with grid and dragdrop files from desctop

 

ajax

 


 

In event onload of dragdrop html5 exaple you have file data  and can use library for image detection. You can more image handling fore eaple image shadowing

Javascript librarys  for image type detection exists in sourceforge.ned and another places

 

 

http://www.pixastic.com/lib/

 

 

Exist FaceRecognition Delphi libraries for example

http://delphideep.blogspot.ru/2013/03/face-recognition-with-delphi.html

 

Hear  how to grap from webcab foto and upload to the base

 

http://forums.unigui.com/index.php?/topic/3642-capturing-camera/

 

after need recognize by delphi recognition library. I do and its work.

Link to comment
Share on other sites

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.   Paste as plain text instead

  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.

 Share

×
×
  • Create New...