简体   繁体   English

Javascript / html - 文件上传

[英]Javascript/html - File upload

I have a news section where I can post some news. 我有一个新闻栏目,我可以发布一些新闻。

-> Thumbnail , title and content - > Thumbnailtitlecontent

What I want: 我想要的是:

  • The user should be able to upload an image file without leaving the page -> progress bar 用户应该能够在不离开页面的情况下上传图像文件 - >进度条

  • Send the file as a post request to my server. 将文件作为发布请求发送到我的服务器。

  • Then I can get the image file from the post request, then I can resize/rename the image and upload it to amazon s3. 然后我可以从post请求中获取图像文件,然后我可以调整大小/重命名图像并将其上传到amazon s3。

  • If I have to use a javascript library, I would prefere to use jquery. 如果我必须使用javascript库,我会优先使用jquery。

This should looks something like this: 这应该是这样的:

上传示例

If I submit the news, I want to save the image path in my database. 如果我提交新闻,我想在我的数据库中保存图像路径。 Now I would need a way to get the image name from my post method. 现在我需要一种从post方法获取图像名称的方法。

I've found some uploading solutions, but I have problems to understand how they are working. 我找到了一些上传解决方案,但是我有一些问题需要了解它们是如何工作的。

http://blueimp.github.com/jQuery-File-Upload/ http://blueimp.github.com/jQuery-File-Upload/

http://www.uploadify.com/ http://www.uploadify.com/

I only know get/post to retrieve information but they integrate somehow php files in the form. 我只知道获取/发布信息,但他们在表单中集成了某些PHP文件。 for example: 例如:

$(function() {
    $('#file_upload').uploadify({
        'swf'      : 'uploadify.swf',
        'uploader' : 'uploadify.php'
        // Put your options here
    });
});

I am lacking information to do this on my own. 我自己缺乏这样做的信息。 What would you recommend me? 你会推荐我什么?

Ps: I am using Java with Play2 Ps:我在Play2上使用Java

You can do something like this from the documentation : 您可以从文档中执行以下操作

$(function() {
    $("#file_upload").uploadify({
        'swf'      : '/uploadify/uploadify.swf',
        'uploader' : '/uploadify/uploadify.php',
        'onSelect' : function(file) {
            alert('The file ' + file.name + ' was added to the queue.');
        }
    });
});

Where you can get the flename once it has been selected. 一旦被选中,你就可以获得flename。

What you're asking for is a LOT really. 你要求的是真的很多。 But to get you started, have a look at this page (uses JQuery): 但是为了帮助您入门,请查看此页面(使用JQuery):

http://tutorialzine.com/2011/09/html5-file-upload-jquery-php/ http://tutorialzine.com/2011/09/html5-file-upload-jquery-php/

The above link is a nice upload utility that you can use for drag-and-drop pretty easily, but it can be used by manually selecting files as well. 上面的链接是一个很好的上传工具,你可以很容易地用于拖放,但它也可以通过手动选择文件来使用。 Well documented. 记录完整。

As for resizing, I've used this with great success (PHP): simpleImage 至于调整大小,我已经非常成功地使用了它(PHP): simpleImage

simpleImage is REALLY easy to use and plug into your website. simpleImage非常易于使用并插入您的网站。

Uploadify is definitely the way to go. Uploadify绝对是最佳选择。 All the steps for implementation are to be found here : http://www.uploadify.com/documentation/uploadify/implementing-uploadify/ 所有实施步骤都可以在这里找到: http//www.uploadify.com/documentation/uploadify/implementing-uploadify/

You need to configure the path where your uploads go in the uploadify.php script. 您需要在uploadify.php脚本中配置上载的路径。

As for amazon S3 here is an implementation : http://code.google.com/p/uploadify-amazon-s3/ 至于亚马逊S3这里是一个实现: http//code.google.com/p/uploadify-amazon-s3/

I think onUploadSuccess method better fits than onSelect : http://www.uploadify.com/documentation/uploadify/onuploadsuccess/ 我认为onUploadSuccess方法比onSelect更适合: http ://www.uploadify.com/documentation/uploadify/onuploadsuccess/

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

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