2

Is there any way I can do that? For example, I have an

<input type="file" id="upload_file" />

Obviously I can't just

$('#upload_file').val('http://www.site.com/path/to/image.jpg').parent().submit();

4 Answers 4

4

You can't do it.

  1. Javascript won't let you read from other domains (for security reasons).
  2. File inputs don't accept URL inputs (or for that matter paths) AFAIK.
Sign up to request clarification or add additional context in comments.

Comments

0

I can't see how you will get this to work. What server side language are you using? Would it not be better to just make a direct request for the remote file from the server?

Comments

0

IF that site supports what are you trying to do it should work. Most of file uploads are very strict, as you can't just upload a file wherever you want even if you know the upload script.

If host supports sending a link to the picture and he knows what to do with it ... I don't see why your script should not work.

<form method="post" action="http://www.example.org/">
     <input type="text" name="upload_file" id="upload_file" value="" />
     <input type="submit" onclick="$('#upload_file').val('http://www.example.org/example.jpg');">
</form>

Comments

0

Te begin with, you cannot do file uploads without a server-side tool. Sending a file to the server is pointless if there isn't anything on the side other to receive it.

Said that, if you already have a server-side language available and a file that's publicly reachable at a URL, the server-side language is perfectly capable of fetching the file by its own means. There's no need to use the browser as intermediary. You just need to send the URL in a regular <input type="text"> element.

If the file is not publicly reachable, e.g., it belongs to an intranet or is password-protected, it's probably simpler to instruct the user to type the URL in the browser's "Open file" dialoque. In many cases, the browser will download the file and fill the <input type="file"> control with the temporary downloaded file.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.