Jump to content

fopen


otuatail

Recommended Posts

Hi Strange things are hapening on a lynux server. My original website which had been on a Windows based server worked fine. I had my web hosting company move it to a Lynux server. No it doesn't work. This simple code should work.

<?
$data = "Testing";
$fh = fopen("sample.txt","w");
fwrite($fh,$val . "\r\n");
fclose($fh);

$fh = fopen("sample.txt","r");
$val = fgets($fh);
fclose($fh);
echo($val);
?>

I get an error on fopen

Warning: fopen(sample.txt): failed to open stream: Permission denied in /home/fhlinux190/d/des-otoole.co.uk/user/htdocs/fopen.php on line 3

Any sugestions please.
Link to comment
Share on other sites

the problem is that fopen tries to open the file, but the server sends the message "you are not autherized to access this file" back to php. The previous post is correct, you need to chmod the file. chmod'ing is basicly telling the computer what people are allowed to access the file.

777 = everyone and their brother in law can read/write/execute the file.

here is a tutorial I found online that explains chmod'ing [url=http://catcode.com/teachmod/]link[/url]. You should have FTP access to your site, (that's how most people upload their files to the server) and most FTP programs will allow you to change permissions of files (chmod). If you dont have a FTP program, [url=http://www.snapfiles.com/reviews/FTP_Wanderer/ftpwanderer.html]here[/url] is a pretty good one that's freeware and allows you to change permissions by right clicking on the files and choosing "properties".

Joe
Link to comment
Share on other sites

in ftp surfer, login to your ftp site. right click file, choose "change permissions". check mark : read / write under owner and group. try again, if nothing happens, try checking read / write under owner, group, and other. should fix it for you.

Joe
Link to comment
Share on other sites

When you upload your files you are supposed to upload them to special area, which from looking what was posted earlier, you are supposed to upload your files to the htdocs folder. When you upload a file you are going to be using PHP to open that file to read/write contents to you'll need to set some permission for that file. Which you can do by Right clicking the file and selecting properties from the menu within your FTP program. Somewhere in the properties dialog box you should find a CHMOD area. It'll either be a textbox, with about 9 textboxes. What you'll want to do is the change the number so it reads 0775. Once it reads 0775 or 775 the file will now the correct permissions for PHP to opne/read and write to the file.
Link to comment
Share on other sites

I can't right click and change permisions BUT I received this email from the web provider.

It appears that the apache has got the permission to access these files, you will need to set these file permissions to writeable and readable to all users.

Using a secure shell program, such as PuTTY, you can access your domain's home directory and carry out advanced maintenance, such as changing file permissions.

Shell access details for your site
Host address:
Username:
Password:

Do I need to buy software called PuTTY. Tried creating a new profile inftpsurfer ssh.des-otoole.co.uk but no use. I am totlay lost on this. Things worked great under wWindows but slow.

Desmond.

[b]PLESE DO NOT POST PRIVATE INFORMATION ON FORUMS, I HAVE REMOVED THE SHELL ACCESS INFO[/b]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.