如果文件上传不可用,CakePHP 会回退到 URL
我正在使用 CakePHP 作为网络应用程序来上传照片。理想情况下,如果无法上传图像(即 iPad/iPhone),我想为用户提供一个选项,从互联网上的某个位置提供图像 URL。
我的观点是:
echo $form->file('img');
现在,在控制器端,我正在使用一个组件来上传图像,这需要图像路径、大小等......所以我想做的是提供 URL 图像代替上传的文件进行处理。我该怎么办?我正在考虑使用 jQuery 将上述输入的 val() 设置为 URL 路径?
这是最佳实践吗?
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 the best practice?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我只是使用第二个字段(文本)。
当然,您可以使用 jquery 隐藏其他字段,并使用单选按钮或选择框切换它们。
在后端,如果传递了 url,我首先抓取文件。下载后,我对其进行处理并“伪造”上传(将其作为上传数据数组存储到 $this->data 中,就像正常上传一样)。然后,上传组件假定它已上传,并且一切都与正常上传一样。
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.