Welcome Guest, Not a member yet? Register   Sign In
uploading using ajax and uploading class
#1

[eluser]phazei[/eluser]
I created a form that is submitted through ajax. When I submit I get the error "You did not select a file to upload."

The form field names are correct. If I change it to a normal submit button, it works just fine. But when I use ajax something goes wrong.

If I do a print_r on $_POST and $_FILES the $_POST has the file name listed with the correct array key, but the $_FILES array is empty.

I'm not certain if CI allows use of the $_FILES array, but I'm guessing it does. Since the post has the name, something is going through. What could be the problem?
Assuming the $_FILES array is working, I'm inclined to believe the problem lays with the ajax, but I'm not sure.

I'm using the correct enctype on the form.

Oh, and I'm doing the ajax through jQuery and the jQuery Form Plugin( http://malsup.com/jquery/form/ ) which seems fairly popular.

Ideas?

Thanks.
#2

[eluser]taewoo[/eluser]
hmm.. i didn't know jquery had a ajax upload..

i was going to say, try and use swfupload.. but i guess it'll work fine
#3

[eluser]phazei[/eluser]
I figured it out. There must be some law that states, 'You may only discover the answers to the problems you've spent way to much time on, 5 minutes after you post for a solution.'

I suppose after you post you stop racking your mind so the solution comes to you... like not disabling the <input type=file> in the preSubmit function without using setTimeout...


Flash is inaccessible to too many users, and javascript is so nice.

This is great:
http://valums.com/wp-content/uploads/aja...jquery.htm


I implemented example 1 with a much more flexible plug-in than that one.
#4

[eluser]Référencement Google[/eluser]
If you implemented a solution, why not posting your code here, that can then be discussed with others and you can also help people.
#5

[eluser]Iverson[/eluser]
[quote author="Too Pixel" date="1234285105"]If you implemented a solution, why not posting your code here, that can then be discussed with others and you can also help people.[/quote]

I was just about to say the same thing 8-/
#6

[eluser]cwt137[/eluser]
LOL. There is no such thing as AJAX file upload. That is just a marketing name. This is what the demo does. There is a iframe on the page. When you fill out the form and pick a file to upload, the target is the iframe. This way the main page doesn't reload, only the iframe. Once the iframe reloads, there is JS code to tell the main page that the file upload is finished. jQuery just makes the JS code a little bit simpler.
#7

[eluser]Iverson[/eluser]
[quote author="cwt137" date="1234298517"]LOL. There is no such thing as AJAX file upload. That is just a marketing name. This is what the demo does. There is a iframe on the page. When you fill out the form and pick a file to upload, the target is the iframe. This way the main page doesn't reload, only the iframe. Once the iframe reloads, there is JS code to tell the main page that the file upload is finished. jQuery just makes the JS code a little bit simpler.[/quote]

True. I knew that but I guess it's still good to make sure others know. Just more proof that people throw around buzz words like "Web 2.0" and "AJAX" without justification, lol. No asynchrony in uploading!
#8

[eluser]phazei[/eluser]
It's true that in using the iframe that particular part isn't AJAX (but it could possibly be considered 'Ajax' [note non acronym form] being more of a concept). Though that particular form script does use AJAX when there is no input type='file'. I am also using an AJAX call on a setInterval to continually query for both upload percent using PECL's APC along with APC's shared memory functions for IPC to get the status of what it's doing with the file and a number of database calls and conversions as it's processing. So while there are no XMLHttpRequest's on the file upload specifically, it is surrounded by 'AJAX' calls and functionality. Thus it's not being used without justification.

OTOH, "Web 2.0" is merely a conceptual buzz word that needs no justification to be thrown around.
#9

[eluser]Iverson[/eluser]
Since when did being a buzz word take away the need for justification? :question: If anything, a person should have more justification for using such an obscure and arguable word.

When you mention that you place "Ajax" (acronym or not) in front of another term (in this case "file uploading", it's a safe conjecture that you're referring to the actual term you used....uploading. The XmlHttpRequest is a part of Ajax technology (per the actual article that coined the term). So when you say you're "uploading using ajax", one can see how that would be confusing. Someone else could say they're uploading using CSS (which by your argument, they could be) but most people would associate the two directly. Hence the confusion.
#10

[eluser]Daniel Peraza[/eluser]
I tried to do the same thing using moootools as javascript framework. I had the same problem too. I had to use the $_FILES array directly and an inline frame as a workaround. I'm very busy right now but I'm planning to develop an AJAX media uploader library through FancyUpload. May be someone could take the initiative and begin to do it first. I think this is a common enough problem to deserve a good answer from the community.




Theme © iAndrew 2016 - Forum software by © MyBB