By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,350 Members | 1,309 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,350 IT Pros & Developers. It's quick & easy.

Returning Javascript after file upload to php

P: 14
Well this should be a fiarly simple question to those of you who are experts at php. I have some Javascript on the Client side that uploads a file to a php on my server through a hidden Iframe. I want to return some Javascript to the Iframe.[ <script type='text/javascript'>parent.myObject.myResponseVar = $response;parent.myObject.dclose();</script>]. $response is a php string var that contains the file upload stats (file name Kbs was successfullly uploaded!) or the error code. Any help you could give me will be greatly appreciated!

Thanks,
Chris
Feb 20 '08 #1
Share this Question
Share on Google+
3 Replies


hsriat
Expert 100+
P: 1,654
Well this should be a fiarly simple question to those of you who are experts at php. I have some Javascript on the Client side that uploads a file to a php on my server through a hidden Iframe. I want to return some Javascript to the Iframe.[ <script type='text/javascript'>parent.myObject.myResponseVar = $response;parent.myObject.dclose();</script>]. $response is a php string var that contains the file upload stats (file name Kbs was successfullly uploaded!) or the error code. Any help you could give me will be greatly appreciated!

Thanks,
Chris
Is it using AJAX?...
If yes, then you can call a function in the onreadystatechange function when xmlHttp.readyState==4 && xmlHttp.status==200.

In that function you can manipulate the response text.
Feb 20 '08 #2

P: 14
Is it using AJAX?...
If yes, then you can call a function in the onreadystatechange function when xmlHttp.readyState==4 && xmlHttp.status==200.
In that function you can manipulate the response text.
I am avoiding AJAX because when I use an xmlHttp request to post to my php using the POST method my php only recieves about 900 bytes of the file. The file is an advertiser list and is now 9 Kb's, but will be much larger when the site comes online. In my php I'm using the super global $_REQUEST $fileName =$_REQUEST['fileName'], $fileString=$_REQUEST['contents']. So to post the file I use an hidden Iframe and an old fasioned html hidden input. The workaround I've been using is to have my php write a file mysavestats.txt and then when the Iframe closes I use an ajax post to get the contents of the mysavestats.txt. I would rather have my php send the results of the upload to the iframe in javascript that sets a variable's value in the parent window to the results. Thank you for your response tho.
Feb 20 '08 #3

P: 14
I am avoiding AJAX because when I use an xmlHttp request to post to my php using the POST method my php only recieves about 900 bytes of the file. The file is an advertiser list and is now 9 Kb's, but will be much larger when the site comes online. In my php I'm using the super global $_REQUEST $fileName =$_REQUEST['fileName'], $fileString=$_REQUEST['contents']. So to post the file I use an hidden Iframe and an old fasioned html hidden input. The workaround I've been using is to have my php write a file mysavestats.txt and then when the Iframe closes I use an ajax post to get the contents of the mysavestats.txt. I would rather have my php send the results of the upload to the iframe in javascript that sets a variable's value in the parent window to the results. Thank you for your response tho.
I'd like to thank hsriat for at least responding to this. I know the question may have sounded stupid to those of you who are seasoned php programmers, but I know very little php. I'm a fairly decent Javascript programmer, but anyway I have solved my own problem. After setting up an apache and php on my computer I am able to experiment with php without having to constantly download and upload to my rented serverspace. So this will close this thread. You just use add this to the end of your return string [ "<script type='text/javascript'>dataFeed.dclose.call(); </script>";] . Simple! Remember just put whatever javascript you betwen script tags at the end of your return string!
Later!
Feb 23 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.