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

Working around the fopen() command

AutumnsDecay
100+
P: 170
Hey there.

I've been implimenting FCKEditor into my clients websites so they can update the text and pictures on their own.

The way it is currently setup is that you need to 'login' to gain access to the editor. Once the changes are made, the user will click submit and the editor will write (in HTML) what the user wrote out in rich text.

The way that I have the editor writing to the file is like this:

I use the PHP fopen command to open the file, fwrite to write the contents to the file and save it, and then fclose to close the file.

My issue is that my host randomly decided to globally disable the fopen command. This means that none of my clients are able to update their website. Is there a work around to using the fopen command? Here is the script I use on every page. I have editted the password for security reasons.

[PHP]<?php
if($_REQUEST['thepassword'] == 'password')
{
if(($_REQUEST['content']!=''))
{
print basename($_SERVER['PHP_SELF']) . '<br>';
$file = fopen(basename($_SERVER['PHP_SELF']) . '.content', 'w');
fwrite($file,stripslashes($_REQUEST['content']));
fclose($file);
print '<b>Saved</b><br/><hr/><br/>';

$content = file_get_contents(basename($_SERVER['SCRIPT_NAME']) . '.content');
print $content;
}else{
print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST">';
$sBasePath = "fckeditor/";
$oFCKeditor = new FCKeditor('content') ;
$oFCKeditor->BasePath = $sBasePath ;
$oFCKeditor->Width = 660;
$oFCKeditor->Height = 600;
$oFCKeditor->Value = file_get_contents(basename($_SERVER['SCRIPT_NAME']) . '.content');
$oFCKeditor->Enabled= true;
$oFCKeditor->Create();
print "<input type='hidden' name='thepassword' value='" . $_REQUEST['thepassword'] . "'/>";
print '<br/><input type="submit" name="submit" value="Save"/>';
print '</form>';
}
}elseif($_REQUEST['mode']=='login'){
print '<b>Please enter password:</b>';
print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST">';
print '<input type="password" name="thepassword" value=""/>';
print '<br/><input type="submit" name="submit" value="Login"/>';
}else{
$content = file_get_contents(basename($_SERVER['SCRIPT_NAME']) . '.content');
print $content;
}
print '<br clear="all"/><br/><a href="' . $_SERVER['PHP_SELF'] . '?mode=login">';
print '<font color="#dddddd" size="-2">login</font></a>';
?>[/PHP]

If anyone can give me a quick alternative, it would be greatly appreciated, as right now it looks like I may need to redo all of my clients websites, and I simply don't have the time or man power to do that in a timely manner.

Thanks!
Oct 30 '08 #1
Share this Question
Share on Google+
11 Replies


AutumnsDecay
100+
P: 170
Some forums talk about cUrl. Is it a good solution?

I really need this resolved, as I'm losing money by the minute on this.
Oct 30 '08 #2

code green
Expert 100+
P: 1,726
You could try file_put_contents() .
But are you sure about what has happened?
is it not a file permissions issue?

If you are unable to use files a rewrite using a database may be required
Oct 30 '08 #3

AutumnsDecay
100+
P: 170
Yeah, I contacted the people I have the reseller hosting account through, and they said the globally disabled the fopen command on all their servers due to security issues.

how would I impliment this into a database? I'm not overly familiar with SQL yet, so I'm just in need of a temporary quick fix for the time being.
Oct 30 '08 #4

code green
Expert 100+
P: 1,726
Try file_put_contents()
They might have forgot about that one
Write a string to a file (PHP 5)
int file_put_contents ( string filename, mixed data [, int flags [, resource context]] )
Identical to calling fopen(), fwrite(), and fclose() successively.
Oct 30 '08 #5

AutumnsDecay
100+
P: 170
And where would I enter that into my code?

The exact code is posted above in my original question. If you could help me out that would be greatly appreciated!
Oct 30 '08 #6

code green
Expert 100+
P: 1,726
Replace the following [PHP]if(($_REQUEST['content']!=''))
{
print basename($_SERVER['PHP_SELF']) . '<br>';
$file = fopen(basename($_SERVER['PHP_SELF']).'.content', 'w');
fwrite($file,stripslashes($_REQUEST['content']));
fclose($file);
print '<b>Saved</b><br/><hr/><br/>'; [/PHP] with [PHP]if(($_REQUEST['content']!=''))
{
print basename($_SERVER['PHP_SELF']) . '<br>';
file_put_contents(basename($_SERVER['PHP_SELF']).'.content',
stripslashes($_REQUEST['content']));
print '<b>Saved</b><br/><hr/><br/>'; [/PHP]
Oct 30 '08 #7

AutumnsDecay
100+
P: 170
They disabled the file_put_contents command as well.

I have a feeling I'm pretty well screwed, as far as this goes.

Any alternatives? Again... I just need a quick fix.
Oct 30 '08 #8

code green
Expert 100+
P: 1,726
Tell us who your service provider is so we can avoid ever employing them.
The only alternatives I can think of are cURL and fsockopen().
fsockopen() returns a file pointer, which you can use with fwrite(), fclose() etc.
Open Internet or Unix domain socket connection (PHP 3, PHP 4, PHP 5)
resource fsockopen ( string target [, int port [, int &errno [, string &errstr [, float timeout]]]] )
I have only used fsockpen with FTP so cannot give exact instructions
but it will be something like [PHP]if(($_REQUEST['content']!=''))
{
print basename($_SERVER['PHP_SELF']) . '<br>';
$file = fsockopen("www.yoursite.com/basename($_SERVER['PHP_SELF']).'.content'", "80", $errno,
>$errstr, 180);
fwrite($file,stripslashes($_REQUEST['content']));
print '<b>Saved</b><br/><hr/><br/>'; [/PHP] You may need more work with this
Oct 30 '08 #9

AutumnsDecay
100+
P: 170
Tell us who your service provider is so we can avoid ever employing them.
The only alternatives I can think of are cURL and fsockopen().
fsockopen() returns a file pointer, which you can use with fwrite(), fclose() etc. I have only used fsockpen with FTP so cannot give exact instructions
but it will be something like [PHP]if(($_REQUEST['content']!=''))
{
print basename($_SERVER['PHP_SELF']) . '<br>';
$file = fsockopen("www.yoursite.com/basename($_SERVER['PHP_SELF']).'.content'", "80", $errno,
>$errstr, 180);
fwrite($file,stripslashes($_REQUEST['content']));
print '<b>Saved</b><br/><hr/><br/>'; [/PHP] You may need more work with this


My hosting company is 3ix.com Yeah, don't ever use them. I wish I wasn't.
Oct 30 '08 #10

AutumnsDecay
100+
P: 170
the fsockopen didn't work. And not so much that it didn't work, I got a critical error when I tried to reload the page.

I've never used curl, so I'm not sure how to go about doing that. I wouldn't assume it's too hard, though. Am I correct?
Oct 30 '08 #11

nathj
Expert 100+
P: 938
Is it possible to move host?

Alternatively what was the error you received? Post that and we may be able to assist further.

I must admit it sounds like the host is a bit over-cautious and should be avoided. Also a database re-write may be the ultimate best option,

As for dealing with the client on this, I assume there is a client, I suggest being honest with them and explaining the situation. Most people like the up-front approach and it can often pay dividends in terms of recommendations and while most people like few people really deliver it - a company I worked for once discovered this the hard way,

Cheers
nathj
Oct 31 '08 #12

Post your reply

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