-1

is there any script in html to upload files it should be only 1 html file (can include js , etc) but should be 1 file .html NO php and the path where the file is uploaded (if possible)

  • 4
    No, there isn't. HTML forms need a POST receiver, you cannot initiate a script-free upload so; that would require a PUT request. – mario Sep 29 '12 at 18:16

2 Answers2

2

is there any script in html to upload files it should be only 1 html file (can include js , etc) but should be 1 file .html NO php and the path where the file is uploaded (if possible)

Well your requirement states that you need a 'Pure HTML (and JS)' web page on the client side that will handle the file upload.

Now there are two parts to this..

On the Client side:

  1. We need HTML tags like <input type="file" ... /> embedded in a <form> tag to capture the file to be uploaded.

    2.a. How do you want to send the file..? Should it be when the users submits the page then all you need to do is have the action attribute of the <form> point to the PHP page sitting on the server to accept the data been sent across.

    2.b. Maybe you want to send the file asynchronously (in the background). Well in this case you could use several JQuery AJAX File uploader plugins to do this for you. Google could turn up quite a few results.

    Note that on HTML4 browsers the ONLY way you can send a file to the server is when a form is submitted - so technically a one page AJAX isn't possible here. But the illusion of a async file upload is created by using a hidden iframe to do the upload. Luckily we have great plugins that make it easy like Plupload and Uploadify, the later which I have used once. Note that these plugins also allow you to use Flash/Silverlight uploaders which is not in your requirements. Needless to say, Silverlight/Flash allow for a async file upload.

    2.c. HTML5 async file upload: Basically HTML5 replaces Flash/Silverlight by caching the file in memory and then we use JQuery to send it across using AJAX..

    I found this tut a few months ago that explains this well :) : http://tutorialzine.com/2011/09/html5-file-upload-jquery-php/

Finally on the Server side:

  1. Here you would have a basic PHP script that will read the binary data of the file from the variable $_FILES['<name of input file tag in the form>']

Hope this helps! Hey do let me know how you finally decide to proceed with this.

All the best!

Kent Pawar
  • 2,378
  • 2
  • 29
  • 42
  • i cant use php there dude :\ ...... i only can edit the html file .... so is there any way to upload or include a php file??? can we include the php file from another server using html ..... so that i can work on that server and can upload the php later onn – user1708712 Sep 30 '12 at 04:37
  • Oh ok.. Seems like you don't have rights to upload PHP code onto the server but can host HTML files there.. Is this the case? – Kent Pawar Sep 30 '12 at 06:04
  • 1
    @user1708712 dude I guess you need to check wit ur hosting provider as they might have some pre-installed PHP plugins for this. As I have explained above, there is NO other way around this.. probably they don't want users to upload anything.. check their Terms of Service doc.. – Kent Pawar Sep 30 '12 at 11:09
0

No, you will need a server-side application process it (PHP, ASP.NET, a CGI executable, etc). Sorry

Adam Plocher
  • 13,994
  • 6
  • 46
  • 79