5

There might not be an answer for this, but I will still ask anyway, since I can't find anything in Google. I have a file upload site created using php and HTML5 mostly. I know that, using HTML5 chunking system, I can do some sort of pause and resume file upload by checking in the server which chunk have been uploaded. But it required the user to try upload the same file in order for it to work.

Now, I was wondering is there anyway, to get the user full file path, during the the first time user try to upload that file, so that I save that path into database. if something happened, in the site I can just tell user click here to resume (then since I have the file path, I can just auto submit, instead of requiring the user to try browse that file again).

I know if using java we are able to do that (using a signed certificate), but is there anyway using preferable php or javascript or html5 to be able to do this. I'm trying to avoid java. Or maybe any other language?

NOTE: This file upload is for huge upload (ranging from 1MB - 4GB files) and so far it works perfectly fine. It's just I'm trying to add pause/resume feature to this project.

I don't mind to buy trusted certificate or smtg for this to work

Or is there anyway, maybe to use silverlight to get the filepath, and then after I have the filepath, autosubmit it in html form for my php to processed the pause resume feature

Thank you

Harts
  • 4,023
  • 9
  • 54
  • 93
  • 4
    You won't be able to get the file path with JS – romo Jul 01 '13 at 22:20
  • javascript security restrictions will prevent such a thing. allowing server-side code to specify a client-side file for upload would allow a malicious server to try and upload **ANY** file on the client machine which the server knew a path for. – Marc B Jul 01 '13 at 22:31
  • 2
    since the file handle will be broken on a reload, you have to first store the file data locally, localStorage for small files, indexedDB for big ones. you can then resume from the cache instead of from the file. – dandavis Jul 01 '13 at 22:31
  • @dandavis: Define "big ones". session/local/db storage have default limits set at 5-30 MB. No file worth the effort of resuming will fit in that. – SpliFF Jul 15 '13 at 15:13
  • @SpliFF: indexedDB allows more than 30MB. It's exact limit depends on hard drive free space in chrome. I would offer that need relates more to bandwidth than storage space. a 5mb file takes ~20mins to upload on a standard modem, certainly an amount of time you don't want to have to repeat, even in half... – dandavis Jul 15 '13 at 15:18
  • It doesn't depend on HD size, it's capped by user setting. Your definition of 'standard modem' sounds like something from the dark ages. Normal DSL or even 3G will typically upload 5MB in under a minute. – SpliFF Jul 15 '13 at 15:20
  • Actual data on storage limits can be found at http://dev-test.nemikor.com/web-storage/support-test/ but it's worth noting that session storage is useless for this purpose (you'll lose it when you close your browser which kind of defeats the purpose of this exercise). – SpliFF Jul 15 '13 at 15:26

3 Answers3

1

You can use FileReader and some kind of local storage to store the image locally and upload from cache. I wrote an example for a similar problem using sessionStorage here: Get complete filepath for cached images

var input = document.querySelector("#imageInput");
input.addEventListener("change", function(e){
    var reader = new FileReader();
    reader.onload = function(evt){
        var newImage = document.createElement("img");
        newImage.src = evt.target.result;
        document.querySelector("body").appendChild(newImage);
        sessionStorage.setItem("image", evt.target.result);
    };
    reader.readAsDataURL(e.target.files[0]);
}, false);

window.addEventListener("load", function(e){
    if(sessionStorage.getItem("image")){
        var newImage = document.createElement("img");
        newImage.src = sessionStorage.getItem("image");
        document.querySelector("body").appendChild(newImage);
    }
}, false);

So all you have to do is reference the cached image.

Community
  • 1
  • 1
Brin Marx
  • 143
  • 5
  • will sessionStorage fit a 4gb file? – dandavis Jul 11 '13 at 03:26
  • 1
    Not even close. Most browsers cap local/session storage to around 5MB (That's Megabytes, not Gigabytes). sqlLite/indexedDB caps around 25MB. Users can override limits in some browsers but you can't assume they will do that. – SpliFF Jul 15 '13 at 15:08
1

AFAIK, due to security reasons, browser will never let you upload a file unless user has hand picked it personally. I mean they won't even let you open the browse window programmatically, user needs to click the browse button or you can't have the file field in your form. But this is all HTML and once you accept the use of a third party plugin like java applets, flash or silverlight then it's another story. You can do whatever you want that way.

But I think this is not a good way and if it was me I would do things a little differently. I would prompt user of the incomplete uploaded file just by their name and not by their path. And to check and see if an uploading file is a new one or resume of an old one, I would calculate its MD5 signature locally and sent to server prior to actually sending the file. And also you need to store the signature of all uploaded files in server so you can compare them in the future. The part that I'm not sure if is feasible to implement or how to do it is telling the browser from which chunk to start uploading the file!

Community
  • 1
  • 1
Mehran
  • 15,593
  • 27
  • 122
  • 221
  • _they won't even let you open the browse window programmatically_ Actually you can by triggering click event. – Ram Nov 11 '13 at 11:37
  • You are right. Perhaps my previous tests were not as accurate as I thought! Thanks for correcting me. – Mehran Nov 11 '13 at 16:24
-2

try to mention the path for the folder and try to enter only the name of the file in database as it does not changes the path and also helps in uploading.

do something like this

 D/abc/<?php $row['fieldname under which file is stored'];?>

now the file gets upload inside d drive under abc folder

Php developer
  • 446
  • 4
  • 18