1685 posts Time is what you desire most, but waste carelessly.
  • Sold between 100 000 and 250 000 dollars
  • Elite Author
  • Bought between 50 and 99 items
  • Referred between 100 and 199 users
  • Grew a moustache for the Envato Movember competition
  • Exclusive Author
  • Has been a member for 4-5 years
  • Envato Studio (Microlancer) Beta Tester
  • Europe
+1 more
Firsh says

I’d like to write a file upload part in a form that does this: Users can browse the files (no need for multiple with flash, they can just create another browse field with a + sign), then fill out the form, then when they hit submit the file uploading begins. If it succeeds the script would write their links in the email and send it along with the form data.

I’ve checked out solutions here, but I’m unsure of the following: Won’t there be time-out or file size limit exceeded error? I don’t yet know what kind of hosting my client has, what happens if I can’t modify these values? The form should handle files between 1-100Mb. My server is set to 200Mb max, but I heard the PHP default is 2Mb. Even if I can change this on the hosting somehow, what about the timeout? Or AJAX somehow guarantees there won’t be a timeout? How does that work. I’d like to handle everything with jQuery-AJAX-POST. And I’d use CodeIgniter’s File Upload class to handle the uploading to the server.

303 posts
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 1 and 9 users
  • Sold between 100 and 1 000 dollars
  • Syrian Arab Republic
Laith says

1- I would suggest you deal with each file individually 2- be careful if you will use something with (FLASH & codeigniter) and the upload area is password ( flash doesn’t sends cookies with HTTP request i think it only sends IE cookies) i did a trick and it worked i can help you with this. 3- Calculate the worst case for the timeout

:P i hope that helps

Cheers

Laith

303 posts
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 1 and 9 users
  • Sold between 100 and 1 000 dollars
  • Syrian Arab Republic
Laith says

1- I would suggest you deal with each file individually 2- be careful if you will use something with (FLASH & codeigniter) and the upload area is password ( flash doesn’t sends cookies with HTTP request i think it only sends IE cookies) i did a trick and it worked i can help you with this. 3- Calculate the worst case for the timeout

:P i hope that helps

Cheers

Laith

Password Protected * :D

5391 posts
  • Australia
  • Bought between 100 and 499 items
  • Envato Studio (Microlancer) Beta Tester
  • Exclusive Author
  • Has been a member for 4-5 years
  • Interviewed on the Envato Notes blog
  • Referred between 1 and 9 users
  • Sold between 1 000 and 5 000 dollars
Australia says

We currently do this on a project we are working on.

Valums ajax uploader stands out a mile, and with some php help from say Laith, I am sure you could get this working for yourself.

2957 posts
  • Australia
  • Community Moderator
  • Elite Author
  • Author had a Free File of the Month
  • Most Wanted Bounty Winner
  • Author had a File in an Envato Bundle
  • Has been a member for 5-6 years
  • Contributed a Blog Post
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
+10 more
dtbaker Volunteer moderator says

You might find it hard to post files by ajax. Post to a hidden iframe instead:

<iframe name="h" src="about:blank" id="h" style="display:none;"></iframe>
<form enctype="mutlipart/form-data" method="post" action="upload_file.php" id="file_form" target="h">
File: <input name="f" type="file" /> <input name="a" value="Attach File" type="submit" /> 
</form>
<form action="submit.php">
<input name="file_urls" id="file_urls" value="" type="hidden" />
Your Name: <input name="name" type="text" /> 
etc..
<input value="Submit Form" type="submit" />
</form>
<script>
function file_has_been_attached(url){
  $('#file_urls').val($('#file_urls').val() + url + ", ");
  alert('The file '+url+' has been attached, please feel free to upload another file');
  $('#file_form')[0].reset();
}
then upload_file.php would do something like this:
// handle file upload of "f" somehow
move_uploaded_file($_FILES['f']['tmp_name'] , '/some/directory/file_name.jpg');
// post back a url to the parent page letting it know a file has been attached
echo "<script> window.parent.file_has_been_attached('/some/url/file_name.jpg'); </script>";
1685 posts Time is what you desire most, but waste carelessly.
  • Sold between 100 000 and 250 000 dollars
  • Elite Author
  • Bought between 50 and 99 items
  • Referred between 100 and 199 users
  • Grew a moustache for the Envato Movember competition
  • Exclusive Author
  • Has been a member for 4-5 years
  • Envato Studio (Microlancer) Beta Tester
  • Europe
+1 more
Firsh says

Thanks dtbaker I think your solution seems to be the best.

1685 posts Time is what you desire most, but waste carelessly.
  • Sold between 100 000 and 250 000 dollars
  • Elite Author
  • Bought between 50 and 99 items
  • Referred between 100 and 199 users
  • Grew a moustache for the Envato Movember competition
  • Exclusive Author
  • Has been a member for 4-5 years
  • Envato Studio (Microlancer) Beta Tester
  • Europe
+1 more
Firsh says

That “mutlipart” typo tricked me for some minutes man :p :D

1685 posts Time is what you desire most, but waste carelessly.
  • Sold between 100 000 and 250 000 dollars
  • Elite Author
  • Bought between 50 and 99 items
  • Referred between 100 and 199 users
  • Grew a moustache for the Envato Movember competition
  • Exclusive Author
  • Has been a member for 4-5 years
  • Envato Studio (Microlancer) Beta Tester
  • Europe
+1 more
Firsh says

It’s looking good already, thank you guys.

How could I stop/cancel the upload?
iframe.setAttribute('src', 'javascript:false;');
remove(iframe);

Is this sufficient or some handlers are left open this way in the PHP (CI)? I don’t want to leave garbage around.

2957 posts
  • Australia
  • Community Moderator
  • Elite Author
  • Author had a Free File of the Month
  • Most Wanted Bounty Winner
  • Author had a File in an Envato Bundle
  • Has been a member for 5-6 years
  • Contributed a Blog Post
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
+10 more
dtbaker Volunteer moderator says

How could I stop/cancel the upload? iframe.setAttribute(‘src’, ‘javascript:false;’);
<a href="javascript:window.frames[0].stop();">cancel upload</a>
or
<a href="javascript:window.frames['h'].stop();">cancel upload</a>
1685 posts Time is what you desire most, but waste carelessly.
  • Sold between 100 000 and 250 000 dollars
  • Elite Author
  • Bought between 50 and 99 items
  • Referred between 100 and 199 users
  • Grew a moustache for the Envato Movember competition
  • Exclusive Author
  • Has been a member for 4-5 years
  • Envato Studio (Microlancer) Beta Tester
  • Europe
+1 more
Firsh says


How could I stop/cancel the upload? iframe.setAttribute(‘src’, ‘javascript:false;’);
<a href="javascript:window.frames[0].stop();">cancel upload</a>
or
<a href="javascript:window.frames['h'].stop();">cancel upload</a>
I have tried that, and also the method from valums, now I’m trying it like
        $("#h").attr('src', 'javascript:false;').replaceWith("<iframe name="\\"h\" class="\\"\"+Math.floor(Math.random()*100)+\"\" src="\\"about:blank\" id="\\"h\"></iframe>")

(there are no double backslashes..) It totally re-creates the iframe even gives it a random class but it won’t stop the upload!! It seems like, but a few seconds later the file magically appears in the uploads folder with 100% done! How can I make it stop? If user tries to upload it again it’ll throw an error that it already exists. I can trick that to show that it has been added but that is only a half solution. If I click cancel I don’t want to see the file appearing ever after. What is wrong?

Even if I choose another one immediately after cancelling, then both files arrive at the server at the same time. It happens in firefox, chrome, didn’t try in the rest.. Even if I CLOSE the whole browser the file gets uploaded. WTH ? Could somebody write me an e-mailt so we could test it somehow? Maybe that complicates things that the client and the server is the same machine but I’m not using the localhost route, the file travels through the net in theory because it shows real speed.

by
by
by
by
by
by