CakePHP fall back to URL if file upload not available
I'm using CakePHP for a web app to upload photos. Ideally i'd like to supply an option for the user to supply an image URL from somewhere on the internet if uploading an image is not possible (ie. iPad/iPhone).
I have this in my view:
echo $form->file('img');
Now, on the controller side, i'm using a component to upload the image, this takes the image path, size, etc... so what i'd like to do is supply the URL image in place of the uploaded file for processing. How would i go about this? I was thinking using jQuery to set the val() of the above input to the URL path?
Is this t开发者_如何学Pythonhe best practice?
i simply use a second field for that (text). of course you can hide the other field with jquery and toggle them with a radio button or select box.
in the backend I first grab the file if an url is passed. After the download I process it and "fake" the upload (storing it into $this->data as an array of upload data just like a normal upload would look like). the upload component then assumes it has been uploaded and everything goes like with normal uploads.
精彩评论