duankui6150 2012-05-14 19:57
浏览 33
已采纳

如何使用PHP / jQuery处理上传的文件?

I have a import file page that has a form with a file input element in it, when the user clicks submit, it sends the file, with a JSON document, to a url which uses PHP to read the file and processes it, then inserts the data into a MySQL database.

My question is, what is the best way to go about handling this import feature on the import page(the user-facing interface)? The technologies I am able to use are, Javascript with jQuery for the import file page, and PHP with Codeigniter for the api for serverside processing.

So far, I read people recommending work arounds using iframes, or HTML5 File Api. Is there a better/safer/easier way to go about creating the file upload feature?

  • 写回答

1条回答 默认 最新

  • dpo60833 2012-05-14 21:06
    关注

    As for usability, for latest browsers i would advice is to use drag & drop upload functionality (that's really cool!) with "old-fashioned" ajax file transfer fallback for old browsers, that is based on flash.

    Look at this jQuery plugin for example: http://blueimp.github.com/jQuery-File-Upload/

    As for security, i would advice to check file mime type if it is possible (if you have PHP fileinfo extension) with PHP. Unfortunately, i am not familiar with Codeigniter (i use ZF), but i am sure that Codeigniter has filters/validators for files.

    Form validation in CI:

    http://codeigniter.com/forums/viewthread/74624/#898858

    http://keighl.com/post/codeigniter-file-upload-validation

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 Oracle Kubernetes服务器集群主节点无法访问,工作节点可以访问
  • ¥15 LCD12864中文显示
  • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
  • ¥15 gsoap生成onvif框架
  • ¥15 有关sql server business intellige安装,包括SSDT、SSMS。
  • ¥15 stm32的can接口不能收发数据
  • ¥15 目标检测算法移植到arm开发板
  • ¥15 利用JD51设计温度报警系统
  • ¥15 快手联盟怎么快速的跑出建立模型
  • ¥15 关于腾讯云服务器中,PHP页面无法打开的问题