Avatar of ROM
ROMFlag for United Kingdom of Great Britain and Northern Ireland

asked on 

fakepath ajax post for uploading files to separate php file

Hi All,
I am trying to ajax upload some files as part of a fluid process in the interface. Various things happen to the text file later etc..

I realise that a POST works. But I want to do as part of my ajax with other field information so that I can execute MySQL statements also etc.. etc..

First time I have done through ajax and there is a lot of information out there and numerous multi step procedures ....but cannot follow.

Please can you help me understand what to change so I actually upload the file. I do not need to see the path at all.. but obviously need it for the uploader the other side.

Using:

    var file = document.getElementById("myfilefield").files[0]; //JUST filename.
    var file = document.getElementById("myfilefield").value; // FAKEPATH in path.



Open in new window

I push this into an array with a some various text like user, reference etc.... It is an array as I may do up to 10x at once in the entire process of uploading, interpreting and storing data from the file

but of course the POST is c:\fakepath so my upload fails.

Please advise.

Many thanks in advance

R
PHPjQueryAJAX

Avatar of undefined
Last Comment
ROM
Avatar of ROM
ROM
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

By realise I mean I realise I could do a simple html form with post... but I want to keep this as a one step process for the end users.

Thanks

R
Avatar of ROM
ROM
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

Looks like it might be formdata afterall

    var fd = new FormData();    
                    fd.append( 'someinfo', $(filebox3)[0].files[0]);


Please advise.. thanks
Avatar of ROM
ROM
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

ok got this working with formdata amazingly.... but that is isolated... 
Avatar of ROM
ROM
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

Now I need to blend that success into the rest of the data I want to send to the php file...

And make it work across several files also.

Here goes

R
Avatar of ROM
ROM
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

Feeling like this is a 2 step process.

Do a formdata ajax call to push files up there.
then on success of that call (as in within success:) then perform the second step on uploaded files providing all uploaded ok.

Any comments?

Thanks in advance R
Avatar of leakim971
leakim971
Flag of Guadeloupe image

what about using a new PHP page/code to do that both call?
so it receive all files an dispatch to separate php files and give back a clean message to your ajax call
Avatar of ROM
ROM
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

Hmm.. I do not quite follow.

I am looking for one ajax call if possible.

a) upload of file
b) send information regarding files from form fields in a HTML form.. user input.
c) perform the process per file and iterate through
d) report back complete

b, c, d all working fine.

just got a to work as a separate ajax call on multiple files. So without further thought, help, research this is looking like an ajax call to upload files and upon success fire another ajax call to send rest of my data and then the c) step is done there.

Trying to combine the two... but I do not quite follow your suggestion.

Many thanks in advance

R

Avatar of leakim971
leakim971
Flag of Guadeloupe image

I am looking for one ajax call if possible.
Me too

a) upload of file
a) upload fileS and informationS

b) send information regarding files from form fields in a HTML form.. user input.
b) done at a)

c) perform the process per file and iterate through
c) done at a)

d) report back complete
d) done at d)

b, c, d all working fine.
a all working fine

just got a to work as a separate ajax call on multiple files. So without further thought, help, research this is looking like an ajax call to upload files and upon success fire another ajax call to send rest of my data and then the c) step is done there.
One call, multiple files and data

Trying to combine the two... but I do not quite follow your suggestion.
use a PHP script receiving all the files and data which do the dispatch, use server side to do that work insteadyour web browser

this plugin, for example, may help you achieve your task quickly
Avatar of ROM
ROM
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

Thanks very much.

I have tried combining my FormData which is how I successfully got the files uploading with the same ajax call (avoiding fakepath) for other data from another array and some static and it did not work well.

Also could not check the isset post to identify which task I was doing. Seems I needed to dedicate an external PHP file to process the file upload for this and put my other functions in separate PHP files.

This is what is stopping my single ajax send at the moment. Cannot see how I am able to process that right now.

Thank you

R


ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of ROM
ROM
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

Cannot see how that code works.. Apart from a I get the point you may call php files when processing the first php file.
I have resorted to using the success and complete events of ajax.

Either that or I restructure my code to actually perform all operations and report back if problem as part of an exit statement.. Maybe this is what I should have done.

What I have seems to work ok in test for now.

Thank you

R
Avatar of ROM
ROM
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

OK I have looked over.
I can see what you are doing.
I am assuming that the process is submitting the files as you are using file input types. I can see the text also.
This all looks fine on the surface. I need to assume you do not have a fakepath error because you are using a form.. but cannot tell.
Thank you for helping. I do not see anything new though. Which I understand, you do not truly know how far I am along.

But this does not actually help me.

But I have now resolved enough for me at this time to undertake a second ajax call on the complete statement of the first that focusses on uploading the files and circumventing the fakepath issue by using FormData as this is the only method I can see that actually circumvents the fakepath issue experienced by browsers which was my post.

Maybe there are better methods... but this is what I have found myself when troubleshooting this.

Many thanks

R
PHP
PHP

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

125K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo