简体   繁体   English

如何从URL JavaScript和PHP加载文件

[英]How to load file from url javascript & php

I'm facing a problem for hours, and I don't find a solution. 我面临几个小时的问题,但找不到解决方案。

Basically, in my app I load files and pass it to javascript with : 基本上,在我的应用程序中,我加载文件并将其传递给javascript:

<input type="file" multiple onchange="mixer.photo.readfiles(this.files)" />

Then, javascript use the file object and I do some stuff in javascript. 然后,javascript使用文件对象,然后在javascript中做一些事情。

My problem is that I also want to do the same thing FROM an URL parameter (url of an image) : Let's say people arrive to my website with the url https://mywebsite.com?img=imgurl.png I want to handle this imgurl.png, and load it to my javascript exactly the same way that I load a file coming from my "input type=file" 我的问题是我也想通过URL参数(图像的URL)做同样的事情:假设人们使用我要处理的URL https://mywebsite.com?img=imgurl.png到达我的网站此imgurl.png,然后将其加载到我的javascript中,就像我加载来自“输入类型=文件”的文件一样

Then, when people will arrive in my page using a url with parameter, they will not need to upload with the 然后,当人们使用带有参数的网址进入我的页面时,他们将不需要使用

Do you know how I can do that ? 你知道我该怎么做吗?

Thank yoh ! 谢谢哦!

Due to security reasons, browsers does not allow you to read local files that are not explicitly selected by the user (either using input file type or drag and drop). 出于安全原因,浏览器不允许您读取用户未明确选择的本地文件(使用输入文件类型或拖放操作)。

If that was not the case, a malicious website could generate a link with parameters that points to a sensitive file on user system which they can read and upload to server without the user knowing it, which is a serious security flaw. 如果不是这种情况,恶意网站可能会生成带有参数的链接,这些链接指向用户系统上的敏感文件,他们可以在用户不知道的情况下读取并上传到服务器,这是一个严重的安全漏洞。

File objects may be obtained from a FileList object returned as a result of a user selecting files using the element, from a drag and drop operation's DataTransfer object, or from the mozGetAsFile() API on an HTMLCanvasElement. 可以从用户使用元素选择文件后返回的FileList对象,拖放操作的DataTransfer对象或HTMLCanvasElement上的mozGetAsFile()API中获取文件对象。

Source: File Reader 资料来源: 档案阅读器

Using the File API, which was added to the DOM in HTML5, it's now possible for web content to ask the user to select local files and then read the contents of those files. 使用HTML5中添加到DOM中的File API,现在可以使Web内容要求用户选择本地文件,然后读取这些文件的内容。 This selection can be done by either using an HTML element or by drag and drop. 可以通过使用HTML元素或通过拖放来完成此选择。

Source: Using files from web applications 来源: 使用Web应用程序中的文件

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

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