Welcome! Log In Create A New Profile

Advanced

Code Link Popup

Posted by 49646230 - Wynand 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Code Link Popup
October 23, 2013 12:07AM
Hi

for some reason I cannot get this right, the file just does not get created. I am sure this must be possible.

Language: PHP
function winOpen() { window.open(" <?php $readR = file_get_contents($_SERVER[';REQUEST_URI';]); $fileW = basename($_SERVER[';PHP_SELF';]).".txt"; file_put_contents($fileW,$readR); echo basename($_SERVER[';PHP_SELF';]).".txt"; ?> ","Code", scrollbars="1"); } </script>
avatar
Mac
Re: Code Link Popup
October 23, 2013 07:21AM
There is no path to the file specified....

"Given a string containing a path to a file, this function will return the base name of the file."

It appears an overkill...
Re: Code Link Popup
October 23, 2013 08:35AM
Hi Mac

Thanks, I just tried that even though it did not make sense to me. My problem is really the below part, the text file does not get created.

Language: PHP
$readR = file_get_contents($_SERVER[';REQUEST_URI';]); $fileW = basename($_SERVER[';PHP_SELF';]).".txt"; file_put_contents($fileW,$readR);
avatar Re: Code Link Popup
October 23, 2013 09:01AM
Your problem may be this line -

Language: PHP
$fileW = basename($_SERVER[';PHP_SELF';]).".txt";


PHP_SELF returns the file suffix as well, so you are getting -

myFile.php.txt

You need to omit the .php suffix -

Language: PHP
$fileW = basename($_SERVER[';PHP_SELF';], ".php").".txt";

Should give -

myFile.txt
Re: Code Link Popup
October 23, 2013 11:07AM
Hi Mac

thanks got it working. I dont mind the .php suffix. I am allowed to do this right?

Language: PHP
<?php if(isset($_SESSION[';myusername';])){?> <Script type="text/javascript">   function winOpen() { window.open("<?php $readR = file_get_contents(basename($_SERVER[';PHP_SELF';]));$fileW = basename($_SERVER[';PHP_SELF';]).';.txt';; file_put_contents($fileW,$readR); echo basename($_SERVER[';PHP_SELF';]).';.txt';?>","Code", scrollbars="1");   } </script> <?php } ?>
Re: Code Link Popup
October 23, 2013 11:08AM
The problem was the JavaScript not being on the same line
avatar
Mac
Re: Code Link Popup
October 23, 2013 11:17AM
Many ways to skin a cat, so you can do it any way you want....
Sorry, only registered users may post in this forum.

Click here to login