CakePHP: How to capture and upload a photo without tripping a black-hole from the security component?

StackOverflow https://stackoverflow.com/questions/21418134

  •  04-10-2022
  •  | 
  •  

質問

My intent is to create a "take a picture of yourself" feature on a website I'm creating. The hope is to capture a photo via the webcam and assign it to the user.

I assume (perhaps incorrectly):

  1. I need to use jquery to capture the image.
  2. I should upload the image via the user registration form, and reference it's filename via the db and a known path.

Where I'm stuck:

How do I upload an image once captured by jquery? I'm assume there are some jquery scripts I can grab to take the photo... but how do I get the photo properly uploaded without getting blackholed by the security component?

The answers here might be stupid obvious, but I'm just having trouble wrapping my head around it.

役に立ちましたか?

解決

Assuming you're using a normal file field that is populated by jquery, you will need to do something like this:

$this->Form->unlockField('upload_image'); // Set 'upload_image' to the name of your field

(Cookbook reference)

I use this method inside a formHelper that I created to make uploading images easy, it works well.

Edit: incidentally, if using an iPhone or iPad, those devices support taking a picture with the webcam and populating a normal file upload field. I've used an iPhone to upload a webcam picture (taken after the "browse" button is pressed) and it worked fine.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top