-3

I could upload a file using this code :

<!DOCTYPE html>
<html>

<head>
<title>File Upload</title>
<link rel="stylesheet" type="text/css" href="main.css">
</head>

 <body>
<h1>File Upload</h1>
<p>Select a new file to upload. Existing files will be 
 replaced.</p>
<form method="POST" enctype="multipart/form-data">
    <input class="button" type="submit" value="Upload">
</form>
</body>

</html>

but despite a choose file button, a get file button, and by pressing it it will download or stream a file from a URL for example :

https://jngnposwzs-flywheel.netdna-ssl.com/wp-content/uploads/2019/05/Transparent-OrangeWhiteCat-764x1024.png

the file should not appear to the user for saving on the Device, then by pressing the upload button the same process continues

Amin Joon
  • 1
  • 1
  • Are you looking for something like this - https://stackoverflow.com/questions/6306935/php-copy-image-to-my-server-direct-from-url …? – CBroe Sep 08 '20 at 09:22
  • @CBroe Thanks, but i don't want to upload to my server, I want to save in the browser then the user decides, secondly I want it in HTML & javascript – Amin Joon Sep 08 '20 at 09:26
  • Unclear what you actually mean. _“I want to save in the browser then the user decides”_ - you can not save files “in” my browser, and only ask me about it afterwards. _“the file should not appear to the user for saving on the Device, then by pressing the upload button the same process continues”_ - I am unable to extract from that phrasing, what you might actually want to achieve here. – CBroe Sep 08 '20 at 09:29
  • @CBroe Is it Possible to upload directly from URL by pressing upload? – Amin Joon Sep 08 '20 at 09:57
  • First you where talking about a download, now it is upload all of a sudden? Upload to _where_? – CBroe Sep 08 '20 at 09:59
  • @CBroe let me explain deeply. my microcontroller has a flash file system, when a new version coming, the user should upgrade the device, it goes to the local URL that device is online like 192.168.1.10/upload, then the user should choose the new file then upload it, the microcontroller is listening for /upload path and grab the file, now I want to, simplified the process and increase the security which the user should not access the file, my goal is by pressing upload button, the firmware file on the master server that has URL , be ready for upload – Amin Joon Sep 08 '20 at 10:11
  • You can not just switch between an actual file upload, and fetching the data from a URL instead, without making changes to your server-side logic as well. – CBroe Sep 08 '20 at 10:14
  • @CBroe yeah, I know, I want the code to firstly fetch data from the server then upload it – Amin Joon Sep 08 '20 at 10:18
  • How to perform a “fake” file upload using an AJAX request, with arbitrary data, is explained here, https://stackoverflow.com/a/22858914/1427878 _“I want the code to firstly fetch data from the server”_ - if you are talking about remote URLs, then fetching that content using client-side JavaScript will only work, if those URLs are _CORS-enabled_. – CBroe Sep 08 '20 at 10:24

1 Answers1

-1

use

enctype='multipart/form-data'
John V
  • 875
  • 6
  • 12