This forum is in archive mode. You will not be able to post new content.

Author Topic: File permissions in php  (Read 2987 times)

0 Members and 3 Guests are viewing this topic.

Offline lucid

  • #Underground
  • Titan
  • **
  • Posts: 2683
  • Cookies: 243
  • psychonaut
    • View Profile
File permissions in php
« on: November 20, 2012, 05:54:36 AM »
Sorry for such an uninteresting question. But, here goes. For some reason fopen doesn't seem to work for me. Here's the relevant part:

Code: (php) [Select]
$fileName = "file.txt";
$fileHandle = fopen($fileName, 'w') or die("can't open file");
fclose($fileHandle);

When I run it, it simply returns "can't open file". I've made sure to chmod the file to give it write permissions but it still simply won't work.
« Last Edit: November 20, 2012, 06:15:35 AM by lucid »
"Hacking is at least as much about ideas as about computers and technology. We use our skills to open doors that should never have been shut. We open these doors not only for our own benefit but for the benefit of others, too." - Brian the Hacker

Quote
15:04  @Phage : I'm bored of Python

Offline Nerotic7

  • Ultimate Faggot 9001
  • Knight
  • **
  • Posts: 151
  • Cookies: -37
    • View Profile
Re: File permissions in php
« Reply #1 on: November 20, 2012, 06:02:38 AM »
Not familiar with PHP, sorry.  :-[
<@Phage> I was put in place ONLY to take care of you.

Offline ca0s

  • VIP
  • Sir
  • *
  • Posts: 432
  • Cookies: 53
    • View Profile
    • ka0labs #
Re: File permissions in php
« Reply #2 on: November 20, 2012, 12:45:58 PM »
Works fine here. Are you sure that:
- file.txt belongs to the same user than your PHP script is running as, and has +w ?
- file.txt has o+w ?
Have you tried chmod'ing 777 that file?
What have you got in open_basedir php.ini's line?
It is everything I can think about right now...

Offline relax

  • Sir
  • ***
  • Posts: 562
  • Cookies: 114
  • The one and only
    • View Profile
Re: File permissions in php
« Reply #3 on: November 20, 2012, 01:20:02 PM »
check you php.ini file
standard is that you can only write to temp directory

Offline lucid

  • #Underground
  • Titan
  • **
  • Posts: 2683
  • Cookies: 243
  • psychonaut
    • View Profile
Re: File permissions in php
« Reply #4 on: November 20, 2012, 10:54:16 PM »
I've tried chmod 777-ing the php script as well as chmod u+w. I can't do any of that to the file because it won't be created. I suppose I'll look around more in my php.ini file.
"Hacking is at least as much about ideas as about computers and technology. We use our skills to open doors that should never have been shut. We open these doors not only for our own benefit but for the benefit of others, too." - Brian the Hacker

Quote
15:04  @Phage : I'm bored of Python

Offline relax

  • Sir
  • ***
  • Posts: 562
  • Cookies: 114
  • The one and only
    • View Profile
Re: File permissions in php
« Reply #5 on: November 20, 2012, 10:58:27 PM »
I've tried chmod 777-ing the php script as well as chmod u+w. I can't do any of that to the file because it won't be created. I suppose I'll look around more in my php.ini file.
chmod the whole folder

Offline lucid

  • #Underground
  • Titan
  • **
  • Posts: 2683
  • Cookies: 243
  • psychonaut
    • View Profile
Re: File permissions in php
« Reply #6 on: November 20, 2012, 11:34:18 PM »
Hmmm, that didn't work either. Everything other script seems to operate fine could that still mean it's something wrong with my php.ini?
"Hacking is at least as much about ideas as about computers and technology. We use our skills to open doors that should never have been shut. We open these doors not only for our own benefit but for the benefit of others, too." - Brian the Hacker

Quote
15:04  @Phage : I'm bored of Python

Offline geXXos

  • Royal Highness
  • ****
  • Posts: 646
  • Cookies: 178
    • View Profile
Re: File permissions in php
« Reply #7 on: November 20, 2012, 11:40:52 PM »
lucid, have you tried chmod($filename, 0777) ;

Offline lucid

  • #Underground
  • Titan
  • **
  • Posts: 2683
  • Cookies: 243
  • psychonaut
    • View Profile
Re: File permissions in php
« Reply #8 on: November 21, 2012, 12:00:34 AM »
Well so far I have chmod-ed the php file as well as the whole directory. I have done chmod 777, chmod u+w, chmod o+w, chmod u+x, just to be thorough. Nothing has worked. I'm not exactly sure what to look for in my php.ini file considering that everything else works perfectly fine.

I can't chmod the actual file because it doesn't exist. I could create it myself but I thought that was the point of creating it in php  :P
« Last Edit: November 21, 2012, 12:01:19 AM by lucid »
"Hacking is at least as much about ideas as about computers and technology. We use our skills to open doors that should never have been shut. We open these doors not only for our own benefit but for the benefit of others, too." - Brian the Hacker

Quote
15:04  @Phage : I'm bored of Python

Offline relax

  • Sir
  • ***
  • Posts: 562
  • Cookies: 114
  • The one and only
    • View Profile
Re: File permissions in php
« Reply #9 on: November 21, 2012, 01:17:08 AM »
Well so far I have chmod-ed the php file as well as the whole directory. I have done chmod 777, chmod u+w, chmod o+w, chmod u+x, just to be thorough. Nothing has worked. I'm not exactly sure what to look for in my php.ini file considering that everything else works perfectly fine.

I can't chmod the actual file because it doesn't exist. I could create it myself but I thought that was the point of creating it in php  :P

is the folder you want to create the file to on another drive?
try writing to the same folder you have the script in or the /tmp folder

check the php error log, or write the error output (remove the die())


« Last Edit: November 21, 2012, 01:46:17 AM by relax »

Offline lucid

  • #Underground
  • Titan
  • **
  • Posts: 2683
  • Cookies: 243
  • psychonaut
    • View Profile
Re: File permissions in php
« Reply #10 on: November 21, 2012, 01:53:06 AM »
is the folder you want to create the file to on another drive?
try writing to the same folder you have the script in or the /tmp folder

check the php error log, or write the error output (remove the die())



Yeah I'm writing the file to the same directory as the php script. Which is in my home folder. And I have that folder set as the open_basedir and it's worked fine up until now. As for writing the error it brings me back to an old problem. I can't get any errors. I've made thoroughly sure that I enabled all errors in the php.ini too.

Code: [Select]
error_reporting
   error_reporting E_ERROR  E_WARNING  E_PARSE
   Default Value: E_ALL E_NOTICE E_STRICT E_DEPRECATED
   Development Value: E_ALL
   Production Value: E_ALL E_DEPRECATED E_STRICT

I've asked the question on other forums as well yet no one can tell me why I can't get errors even with them enabled.

 :-\ Seems I have two problems now..

EDIT:  :o Seems it works now. Ugh that frustrating moment when your code suddenly works, but you don't know why..

Still never figured out why I can't get errors though.
« Last Edit: November 21, 2012, 01:58:44 AM by lucid »
"Hacking is at least as much about ideas as about computers and technology. We use our skills to open doors that should never have been shut. We open these doors not only for our own benefit but for the benefit of others, too." - Brian the Hacker

Quote
15:04  @Phage : I'm bored of Python

Offline relax

  • Sir
  • ***
  • Posts: 562
  • Cookies: 114
  • The one and only
    • View Profile
Re: File permissions in php
« Reply #11 on: November 21, 2012, 03:35:00 AM »
Yeah I'm writing the file to the same directory as the php script. Which is in my home folder. And I have that folder set as the open_basedir and it's worked fine up until now. As for writing the error it brings me back to an old problem. I can't get any errors. I've made thoroughly sure that I enabled all errors in the php.ini too.

Code: [Select]
error_reporting
   error_reporting E_ERROR  E_WARNING  E_PARSE
   Default Value: E_ALL E_NOTICE E_STRICT E_DEPRECATED
   Development Value: E_ALL
   Production Value: E_ALL E_DEPRECATED E_STRICT

I've asked the question on other forums as well yet no one can tell me why I can't get errors even with them enabled.

 :-\ Seems I have two problems now..

EDIT:  :o Seems it works now. Ugh that frustrating moment when your code suddenly works, but you don't know why..

Still never figured out why I can't get errors though.

did you also turn error report on in php.ini ?

think its named php-error

display_errors = On
html_errors = On
error_reporting = E_ALL | E_STRICT

and yeah check the whole file some stuff are there twice

try the
ignore_repeated_errors = On
on also :/

else how did you install the server?
ill usually install everything with
sudo apt-get install tasksel phpmyadmin
« Last Edit: November 21, 2012, 03:40:24 AM by relax »

Offline lucid

  • #Underground
  • Titan
  • **
  • Posts: 2683
  • Cookies: 243
  • psychonaut
    • View Profile
Re: File permissions in php
« Reply #12 on: November 21, 2012, 10:40:19 AM »
I'll do more checking through the php.ini. Perhaps I missed something. I installed everything with:

pacman -S apache php php-apache mysql.

Otherwise I have no clue. It seems I have to check /etc/php/php.ini more thoroughly.
"Hacking is at least as much about ideas as about computers and technology. We use our skills to open doors that should never have been shut. We open these doors not only for our own benefit but for the benefit of others, too." - Brian the Hacker

Quote
15:04  @Phage : I'm bored of Python

Offline iTpHo3NiX

  • EZ's Pirate Captain
  • Administrator
  • Titan
  • *
  • Posts: 2920
  • Cookies: 328
    • View Profile
    • EvilZone
Re: File permissions in php
« Reply #13 on: November 21, 2012, 09:26:37 PM »
Quote
If you are trying to get this program to run and you are having errors, you might want to check that you have granted your PHP file access to write information to the hard drive. Setting permissions is most often done with the use of an FTP program to execute a command called CHMOD. Use CHMOD to allow the PHP file to write to disk, thus allowing it to create a file.

Have you allowed your php file write access to the hard drive?

This might help:

Quote
you should make sure that the apache user (the exact user name will depend on your setup - often httpd or www-data under Linux) has write access to the directory. You can change the owner to the same user as apache (using chown) and set give the owner write access (e.g. "chmod 755") or you can make it world writable (e.g. "chmod 777")
[09:27] (+lenoch) iTpHo3NiX can even manipulate me to suck dick
[09:27] (+lenoch) oh no that's voluntary
[09:27] (+lenoch) sorry

Offline lucid

  • #Underground
  • Titan
  • **
  • Posts: 2683
  • Cookies: 243
  • psychonaut
    • View Profile
Re: File permissions in php
« Reply #14 on: November 22, 2012, 12:19:54 AM »
Thanks for the help ca0s, relax, skidiot.h, and geXXos. Original issue has been solved.
"Hacking is at least as much about ideas as about computers and technology. We use our skills to open doors that should never have been shut. We open these doors not only for our own benefit but for the benefit of others, too." - Brian the Hacker

Quote
15:04  @Phage : I'm bored of Python

 



Want to be here? Contact Ande, Factionwars or Kulverstukas on the forum or at IRC.