简体   繁体   English

使用jQuery上传图片

[英]Uploading image using Jquery

I have this Html code and I try to save my record in DB 我有此HTML代码,我尝试将记录保存在DB中

<div> 
     <p> Item Name : 
      <input type = 'text' id = 'ItemName' />  
     </p>
     <p> select Image : 
      <input type = 'file' id = 'Image' />
      </p>
     <input type='button' id ='btnSaveItem'>Save </input> 

 </div>

How can I upload a picture and save it using Jquery and PHP? 如何上传图片并使用Jquery和PHP保存? I have not been able to find a Jquery method to upload an image, but I need to do without a page refreshing. 我无法找到一个Jquery方法来上传图像,但是我需要在不刷新页面的情况下进行操作。

Normally you just can't upload images via Ajax, you will need workarounds. 通常,您只是无法通过Ajax上传图像,因此需要变通办法。

I use this jquery plugin, it's easy to use and you don't need to code almost nothing: http://malsup.com/jquery/form/ 我使用了这个jquery插件,它易于使用,并且您几乎不需要编写任何代码: http : //malsup.com/jquery/form/

Not sure if it's possible, but seems to me like every other jquery post-without-refresh :) Put names in the desired fields, not only id's. 不知道是否可能,但在我看来,就像其他所有jquery post-without-refresh :)一样,将名称放在所需的字段中,而不仅仅是id。 Then post to a specific .php page the desired data via jquery, and make your upload logic there. 然后通过jquery将所需的数据发布到特定的.php页面,并在那里进行上传逻辑。 The correspond will be between your jquery and .php page, so no refresh will be done. 对应内容将在您的jquery和.php页面之间,因此不会进行刷新。 The text field you can get with the $_POST superarray in php, and the file with $_FILE. 您可以使用php中的$ _POST超数组获得文本字段,而使用$ _FILE获得文件。

可以使用uploadify进行上传而无需刷新,请参阅http://www.uploadify.com/demos/

I've recently added an answer for a similar question. 我最近添加了一个类似问题的答案。 Please take a look at this: 请看一下这个:

Upload image using jquery 使用jQuery上传图像

It uses $.ajax to upload a file. 它使用$.ajax上传文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM