how to preview uploaded image in php form

家住魔仙堡 提交于 2019-12-25 16:49:18

问题


i created PHP form for my site, with image upload option on it. but it only show the image name before image submitted, but i want to view/preview the image/file before submit so how this possible in this?

 "file36":{"label":"Select/Upload a Student's Photo","accept":"jpg|jpeg|png|gif|bmt","files":true,"attach":true,"database":true,"maxbytes":204800,"fieldtype":"fileupload","required":true,}},

回答1:


As far as I know this is not possible with php until you upload the image. However, you are able to do so with jquery. Check out http://blueimp.github.io/jQuery-File-Upload/




回答2:


The old way is to upload the image to a temp folder, create an iframe and load the response there. Then link the temp image from the iframe to a hidden field in the final form with JavaScript. When you submit the form place the image in the right folder. Finally run a cron job every 24-48h to empty out the temp folder.

The new way is the File API supported in IE10+ and all modern browsers. Fallbacks in Flash and Silverlight exist for older browsers.




回答3:


You obviously misunderstand how file uploads w/ PHP work.

PHP is server side programming language, meaning, it can only execute and access scripts, that are on the server. So, for PHP to access / analyze a picture in any way, it has to be on the server already.

You can upload the file in a temporary directory, analyze it and, if it suits your needs, move to a permanent folder. Otherwise, just delete it.



来源:https://stackoverflow.com/questions/19947355/how-to-preview-uploaded-image-in-php-form

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!