Jump to content

Recommended Posts

[RESOLVED PROBLEM - 22/03/2006]

Hello,
To start off, I have the tendancy to sound confusing when i explain things. Please feel free to query about anything you might not understand!
Please request code you would like to see, besides the two examples below there is ALOT of code and dont want to clutter the first post too much.

I have a html form with the usual "name" "number" etc fields, but it also has a "file" input field. When submit is pressed the form moves to a php script (seperate file). The form beginning looks like:
[!--html--][div class=\'htmltop\']HTML[/div][div class=\'htmlmain\'][!--html1--]<[color=blue]form id[/color]="[color=orange]attach_form[/color]" action="[color=orange]phpScriptFile.php[/color]" method="[color=orange]post[/color]">
....
<[color=blue]input type[/color]="[color=orange]file[/color]" id="[color=orange]filenames[/color]">
<[color=blue]/form[/color]>[!--html2--][/div][!--html3--]

The script then uploads the specified file via php's ftp functions to the server and then adds it to a generated email as an attachment. Then sends the email to bla@bla.bla

With the above structure it works. Everything uploads and sends correctly. BUT now i have been adding Ajax features to my website, to avoid jumping to pages and have things refresh/reloaded all the time. You know, make it look cool! And this is where my problem comes into play.

When i add the Ajax features i make so that the form no longer goes directly to the php script/file. Now it goes through a few JS functions before it gets to the php file. First some validation and then the ajax call.
Before the ajax i was using $_FILES array in php to access the data i needed from the file input field to upload via ftp. Examples of these values/data:

[?PHP]
$docName= $_FILES['filenames']['name'];
$docType= $_FILES['filenames']['type'];
....etc
[/code]

Nothing had to be brought in via $_POST['..'] for the file data, just used $_FILES.
$_FILES as i understand it is a reference to the temp location on the server, of the file made by the file input field in the html. I also read that if one does not use the temp data of the file immediately, it goes away. "POOF! All Gone!"

So now when i use the ajax(JS), by the time the code gets to the php script the $_FILES array is empty!

My question is basically:
Is there a way that i can keep the "file" data alive in JS that i can run through the JS functions and still access the temp data via $_FILES array in the php file? Or even if there might be a different way to access the info which i need after the whole JS traversal?

Thank you upfront!

P.S: What do i use to show php code? As seen above [code=php:0] ... [/code] dont work?
Ajax can not be used to upload files. Javascript is "sandboxed" and can not access the computer's file system, execpt for cookies. You will have to use a "conventional" posted form to upload the file.

Also, how is your file upload working when you are not using the 'enctype="multipart/form-data"' declaration in your form?

Thank you hitman6003, for the information! Started having the idea that even if there was a way it would probably make the code NOT act ajaxian anyway!? :)

For the enctype not added to the form example? It is there (in my code at the office) must have forgotten to add it to the post!!
My bad, please forgive me!! :P

Thank you again.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.