473,396 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Working around the fopen() command

AutumnsDecay
170 100+
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
11 2729
AutumnsDecay
170 100+
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
1,726 Expert 1GB
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
170 100+
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
1,726 Expert 1GB
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
170 100+
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
1,726 Expert 1GB
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
170 100+
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
1,726 Expert 1GB
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
170 100+
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
170 100+
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
938 Expert 512MB
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

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

Similar topics

2
by: Heinz | last post by:
Hi All In a section of my code I open some other file via an URL to have that code executed like in $raw=fopen("http://webserver/some.php?aaa=$a&bbb=$b"); print "<td>$raw<td>"; This works...
1
by: ataru | last post by:
Sorry to ask a semi implementation-dependent question, but I'm having some trouble with fopen() in a Windows environment... I want to open a file a la FILE *f; f=fopen(...
3
by: Lenn | last post by:
Hello, I have the following example of AsyncCallback from a C# book which I wanted to implement in my project: //Class with AsyncDelegate public class AsyncProcess { public AsyncProcess() {
5
by: pkirk25 | last post by:
Problem 1: I need to access a set of files all with same name and all in subdirectories of the directory I run the executable in. Problem 2. I need to edit a file but want to create a .bak first....
10
by: padh.ayo | last post by:
Hi, I have a array structure called people It is properly initialized to 100 array structure elements. Now, I'm reading in from the command line a txt file, and I get them to open correctly. In...
6
by: rfhurley | last post by:
I'm a newbie at this... I'm trying to run a PHP script from the W3C PHP tutorial, and the example shows the following code: <html> <body> <?php $file=fopen("welcome.txt","r"); ?>
25
by: subramanian100in | last post by:
Consider the following program: #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv) { if (argc != 2) { printf("Usage: <program-name<text-file>\n");
3
by: nihad.nasim | last post by:
Hi, I am kind of new to PHP and while learning I came across the touch command which creates a new file. I also came up with fopen to open a file. In both cases I am having the same problem: ...
10
by: Stephen.Schoenberger | last post by:
Hello, Sorry if this is not "exactly" a C topic but I thought this would be the best place to start. I need some guidance on working with bitmap images in ANSI C. I need to "read" in a bitmap...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.