douwo6738 2011-11-24 09:40
浏览 86
已采纳

通过ajax将图像上传到webserver,并将给定的文件名插入数据库

Im currently working on a project that requires the following.

  • I need to be able to upload an image (further scope for multiple images)
  • To an area of a webserver, rename the name of the uploaded images to what I want them to be (i.e a specific string that I state with say incrememnts on _1 _2 for multiple images e.t.c)
  • Done via ajax, as I do not want page reloads.
  • Add the returned file name/s into a db.

I have done image uploads before with php, however using the rand to generate a name and return it via post, but not via ajax, Ive done all the bits above before seperately, but not all to gether...

Ive done a quick google search, and none of them seem to work the way that I want them to.

I liked the working of this http://www.zurb.com/playground/ajax_upload but I cant for the life of me get it to work.

Thanks :)

  • 写回答

2条回答 默认 最新

  • duanluan2047 2011-11-24 09:59
    关注

    As far as I know, an Upload using AJAX only is not possible. However, there is some kind of workaround for this. You can use a normal file upload (see http://www.php.net/manual/en/features.file-upload.php for details). Your browser will then try to display the response of the POST you just did. Therefore, you need to point the frame target of your form to a new invisible iframe, so your page content doesnt get changed. You can use the response to the POST to send new javascript code to the browser which for example can display some feedback for the user or display the image you just uploaded. The prototype library ( http://www.prototypejs.org/ ) will help you on some of these tasks.

    The link above will also give you hints about how to rename the file, store it on your web server, or even store it in the db. The latter method is not recommended.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗