FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Having trouble writing/copying/renaming file to sub-directory
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Having trouble writing/copying/renaming file to sub-directory [message #170966] Mon, 13 December 2010 04:25 Go to next message
seeWebInstead is currently offline  seeWebInstead
Messages: 14
Registered: October 2010
Karma: 0
Junior Member
Using the FTP program, I PUT the PHP script files, created some
sub-directories, including ReqSOAP, and PUT a file into the ReqSOAP
sub-directory. Excerpts of directory listings after that's been done:

ftp> dir
...
drwxr-xr-x 3 3237 vhosts 4096 Nov 20 23:41 Images
drwxr-xr-x 2 3237 vhosts 4096 Dec 11 02:10 RepSOAP
drwxr-xr-x 2 3237 vhosts 4096 Dec 13 10:56 ReqSOAP
...
-rw-r--r-- 1 3237 vhosts 20059 Nov 11 13:42 portal1.php
...
ftp> cd ReqSOAP
250 OK. Current directory is /ReqSOAP
ftp> dir
-rw-r--r-- 1 3237 vhosts 5 Dec 13 10:56 tmp.txt

Using PHP script, writing into my toplevel (default) directory
works, but that's not what I want, which is to write into a
sub-directory. (What's the point of making sub-directories if they
can't be used from PHP scripts??) Here's the key part of the script,
interleaved with the corresponding output:

$olddir = getcwd(); echo " old-dir: "; var_dump($olddir);
old-dir: string(46) "/www/blackapplehost.com/c/a/l/calrobert/htdocs"

echo " strlen=",strlen($outr20str)," ";
strlen=791

$filnam = $timst . ".txt"; echo " filnam: [",$filnam,"] ";
filnam: [1292127412.58842300.txt]

$dir = "ReqSOAP"; echo " is_dir: ",is_dir($dir)," ";
is_dir: 1

$filename = "$dir/$filnam"; echo " filename: [",$filename,"] ";
filename: [ReqSOAP/1292127412.58842300.txt]

$bytes = file_put_contents($filename,$outr20str); echo " f1: "; var_dump($bytes);
f1: bool(false)

$bytes = file_put_contents($filnam,$outr20str); echo " f2: "; var_dump($bytes);
f2: int(791)

$r = copy($filnam, $filename); echo " copy: "; var_dump($r);
copy: bool(false)

$r = link($filnam, $filename); echo " link: "; var_dump($r);
link: NULL

$r = unlink($filnam); echo " unlink: "; var_dump($r);
unlink: bool(true)

I've run out of ideas how to get my output into the ReqSOAP sub-directory.
Re: Having trouble writing/copying/renaming file to sub-directory [message #170967 is a reply to message #170966] Mon, 13 December 2010 04:49 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 12/12/2010 11:25 PM, Robert Maas, http://tinyurl.com/uh3t wrote:
> Using the FTP program, I PUT the PHP script files, created some
> sub-directories, including ReqSOAP, and PUT a file into the ReqSOAP
> sub-directory. Excerpts of directory listings after that's been done:
>
> ftp> dir
> ..
> drwxr-xr-x 3 3237 vhosts 4096 Nov 20 23:41 Images
> drwxr-xr-x 2 3237 vhosts 4096 Dec 11 02:10 RepSOAP
> drwxr-xr-x 2 3237 vhosts 4096 Dec 13 10:56 ReqSOAP
> ..
> -rw-r--r-- 1 3237 vhosts 20059 Nov 11 13:42 portal1.php
> ..
> ftp> cd ReqSOAP
> 250 OK. Current directory is /ReqSOAP
> ftp> dir
> -rw-r--r-- 1 3237 vhosts 5 Dec 13 10:56 tmp.txt
>
> Using PHP script, writing into my toplevel (default) directory
> works, but that's not what I want, which is to write into a
> sub-directory. (What's the point of making sub-directories if they
> can't be used from PHP scripts??) Here's the key part of the script,
> interleaved with the corresponding output:
>
> $olddir = getcwd(); echo " old-dir: "; var_dump($olddir);
> old-dir: string(46) "/www/blackapplehost.com/c/a/l/calrobert/htdocs"
>
> echo " strlen=",strlen($outr20str)," ";
> strlen=791
>
> $filnam = $timst . ".txt"; echo " filnam: [",$filnam,"] ";
> filnam: [1292127412.58842300.txt]
>
> $dir = "ReqSOAP"; echo " is_dir: ",is_dir($dir)," ";
> is_dir: 1
>
> $filename = "$dir/$filnam"; echo " filename: [",$filename,"] ";
> filename: [ReqSOAP/1292127412.58842300.txt]
>
> $bytes = file_put_contents($filename,$outr20str); echo " f1: "; var_dump($bytes);
> f1: bool(false)
>
> $bytes = file_put_contents($filnam,$outr20str); echo " f2: "; var_dump($bytes);
> f2: int(791)
>
> $r = copy($filnam, $filename); echo " copy: "; var_dump($r);
> copy: bool(false)
>
> $r = link($filnam, $filename); echo " link: "; var_dump($r);
> link: NULL
>
> $r = unlink($filnam); echo " unlink: "; var_dump($r);
> unlink: bool(true)
>
> I've run out of ideas how to get my output into the ReqSOAP sub-directory.

What's the userid php is running under?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Having trouble writing/copying/renaming file to sub-directory [message #170968 is a reply to message #170967] Mon, 13 December 2010 06:28 Go to previous messageGo to next message
seeWebInstead is currently offline  seeWebInstead
Messages: 14
Registered: October 2010
Karma: 0
Junior Member
> From: Jerry Stuckle <jstuck...@attglobal.net>
> What's the userid php is running under?

Trying to find that info...

var_dump($_ENV);
array(5) { ["PATH"]=> string(28) "/usr/local/bin:/usr/bin:/bin"
["PWD"]=> string(1) "/"
["LANG"]=> string(1) "C"
["SHLVL"]=> string(1) "1"
["_"]=> string(17) "/usr/sbin/apache2" }
That didn't tell me anything useful.

$uid = posix_getuid(); var_dump($uid);
int(2001)
Is that what you wanted to know?
Re: Having trouble writing/copying/renaming file to sub-directory [message #170969 is a reply to message #170968] Mon, 13 December 2010 08:12 Go to previous messageGo to next message
alvaro.NOSPAMTHANX is currently offline  alvaro.NOSPAMTHANX
Messages: 277
Registered: September 2010
Karma: 0
Senior Member
El 13/12/2010 7:28, Robert Maas, http://tinyurl.com/uh3t escribió/wrote:
>> From: Jerry Stuckle<jstuck...@attglobal.net>
>> What's the userid php is running under?
>
> Trying to find that info...
[...]
> $uid = posix_getuid(); var_dump($uid);
> int(2001)
> Is that what you wanted to know?

Then it's clear why you can't write on it:

drwxr-xr-x 2 3237 vhosts 4096 Dec 11 02:10 RepSOAP

You need to set the "w" (write) permission for other users. You can
probably do it with your FTP client.


--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
Re: Having trouble writing/copying/renaming file to sub-directory [message #170974 is a reply to message #170968] Mon, 13 December 2010 12:12 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 12/13/2010 1:28 AM, Robert Maas, http://tinyurl.com/uh3t wrote:
>> From: Jerry Stuckle<jstuck...@attglobal.net>
>> What's the userid php is running under?
>
> Trying to find that info...
>
> var_dump($_ENV);
> array(5) { ["PATH"]=> string(28) "/usr/local/bin:/usr/bin:/bin"
> ["PWD"]=> string(1) "/"
> ["LANG"]=> string(1) "C"
> ["SHLVL"]=> string(1) "1"
> ["_"]=> string(17) "/usr/sbin/apache2" }
> That didn't tell me anything useful.
>
> $uid = posix_getuid(); var_dump($uid);
> int(2001)
> Is that what you wanted to know?

You need to learn about Linux administration and permissions.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Having trouble writing/copying/renaming file to sub-directory [message #170980 is a reply to message #170969] Mon, 13 December 2010 18:37 Go to previous messageGo to next message
seeWebInstead is currently offline  seeWebInstead
Messages: 14
Registered: October 2010
Karma: 0
Junior Member
> From: =?ISO-8859-1?Q?=22=C1lvaro_G=2E_Vicario=22?= <alvaro.NOSPAMTH...@demogracia.com.invalid>
> Then it's clear why you can't write on it:
> drwxr-xr-x 2 3237 vhosts 4096 Dec 11 02:10 RepSOAP
> You need to set the "w" (write) permission for other users. You can
> probably do it with your FTP client.

Yes, FTP does support chmod. I tried setting permission 777:
drwxrwxrwx 2 3237 vhosts 4096 Dec 14 01:27 ReqSOAP
and that fixed the problem. But allowing anyone anyone in the whole
world to write to this sub-directory seems a bad idea, so next I
backed it off to just 775:
drwxrwxr-x 2 3237 vhosts 4096 Dec 14 01:27 ReqSOAP
and it still was writable by my PHP script, so I hope that's safe
enough. All files in this directory (including the one I'm writing
now) will be public-key signed and encrypted, so if other users in
the same group write junk there, overwriting my own files during
the brief interval after I write them before a callback mechanism
fetches them, the worst it can do is disrupt message passing, not
insert forged messages. (The same will be true of reply messages in
another similar sub-directory, where there will be a brief interval
after a call-forward mechanism writes them until the local PHP
script fetches them.)

Thanks.
Re: Having trouble writing/copying/renaming file to sub-directory [message #170981 is a reply to message #170974] Mon, 13 December 2010 19:03 Go to previous messageGo to next message
seeWebInstead is currently offline  seeWebInstead
Messages: 14
Registered: October 2010
Karma: 0
Junior Member
> From: Jerry Stuckle <jstuck...@attglobal.net>
(regarding my PHP/MySQL hosting account on blackapplehost.com)
> You need to learn about Linux administration and permissions.

From the information I posted, i.e. how my directory looks via FTP,
and how my PHP scripts run, how can you tell it's Linux, as opposed
to FreeBSD or Windows?? I suppose the fact that the directory
separator is / instead of \ eliminates Windows? But otherwise, how
can you pin down which version of *nix it's running??

By the way, when I first had this problem, I suspected the system
was running Windows, and thus the directory separator wasn't / but
was \, so I changed the directory separator in my filename spec to
be \, and it successfully wrote the file!! But then when I used FTP
to see if it was written in the subdirectory, nothing was there,
the sub-directory was still empty. But then I noticed the main
directory contained a file called "ReqSOAP\1292127412.58842300.txt",
but when I tried to GET that file via FTP (to see if PHP had
written the correct data into it) it complained it had a prohibited
name. FTP couldn't rename it either, because of the prohibited
filename. Next I tried mget *292*.txt, and it recognized the file
and offered to get it, but when I said 'y' it said the name was
prohibited. I finally used a PHP script to rename the file to have
a more normal filename, at which point FTP could GET it and then
delete it.
Re: Having trouble writing/copying/renaming file to sub-directory [message #170983 is a reply to message #170981] Mon, 13 December 2010 19:14 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 12/13/2010 2:03 PM, Robert Maas, http://tinyurl.com/uh3t wrote:
>> From: Jerry Stuckle<jstuck...@attglobal.net>
> (regarding my PHP/MySQL hosting account on blackapplehost.com)
>> You need to learn about Linux administration and permissions.
>
> From the information I posted, i.e. how my directory looks via FTP,
> and how my PHP scripts run, how can you tell it's Linux, as opposed
> to FreeBSD or Windows?? I suppose the fact that the directory
> separator is / instead of \ eliminates Windows? But otherwise, how
> can you pin down which version of *nix it's running??
>

FreeBSD is a version of Linux. And Windows does not have the same
permissions. And it doesn't matter which version of Linux you are
running - your problem is the same on all of them.

But then I understand various operating systems - so it was quite obvious.

> By the way, when I first had this problem, I suspected the system
> was running Windows, and thus the directory separator wasn't / but
> was \, so I changed the directory separator in my filename spec to
> be \, and it successfully wrote the file!! But then when I used FTP
> to see if it was written in the subdirectory, nothing was there,
> the sub-directory was still empty. But then I noticed the main
> directory contained a file called "ReqSOAP\1292127412.58842300.txt",
> but when I tried to GET that file via FTP (to see if PHP had
> written the correct data into it) it complained it had a prohibited
> name. FTP couldn't rename it either, because of the prohibited
> filename. Next I tried mget *292*.txt, and it recognized the file
> and offered to get it, but when I said 'y' it said the name was
> prohibited. I finally used a PHP script to rename the file to have
> a more normal filename, at which point FTP could GET it and then
> delete it.

Shows how little you actually know.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Having trouble writing/copying/renaming file to sub-directory [message #170988 is a reply to message #170983] Tue, 14 December 2010 03:26 Go to previous messageGo to next message
Adam Harvey is currently offline  Adam Harvey
Messages: 25
Registered: September 2010
Karma: 0
Junior Member
On Mon, 13 Dec 2010 14:14:01 -0500, Jerry Stuckle wrote:
> FreeBSD is a version of Linux.

No, it's not.

Adam
Re: Having trouble writing/copying/renaming file to sub-directory [message #170991 is a reply to message #170988] Tue, 14 December 2010 04:59 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 12/13/2010 10:26 PM, Adam Harvey wrote:
> On Mon, 13 Dec 2010 14:14:01 -0500, Jerry Stuckle wrote:
>> FreeBSD is a version of Linux.
>
> No, it's not.
>
> Adam

I would suggest you learn what you're talking about. FreeBSD may have
been developed separately, but it is as much a Unix clone as Linux is,
and is generally considered in the same vein as other Linux versions.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Having trouble writing/copying/renaming file to sub-directory [message #170992 is a reply to message #170991] Tue, 14 December 2010 05:44 Go to previous messageGo to next message
Jeremy J Starcher is currently offline  Jeremy J Starcher
Messages: 5
Registered: December 2010
Karma: 0
Junior Member
On Mon, 13 Dec 2010 23:59:39 -0500, Jerry Stuckle wrote:

> On 12/13/2010 10:26 PM, Adam Harvey wrote:
>> On Mon, 13 Dec 2010 14:14:01 -0500, Jerry Stuckle wrote:
>>> FreeBSD is a version of Linux.
>>
>> No, it's not.
>>
>> Adam
>
> I would suggest you learn what you're talking about. FreeBSD may have
> been developed separately, but it is as much a Unix clone as Linux is,
> and is generally considered in the same vein as other Linux versions.

Actually, FreeBSD might be more of a Unix clone than Linux is, but ...

that does not make it a version of Linux. It makes it a Unix-like OS.

* FreeBSD does not run the Linux kernel (which is the only part of
Linux that actually is Linux)
* It is not byte-code compatible with Linux.
* It is not 100% source compatible with Linux.
Re: Having trouble writing/copying/renaming file to sub-directory [message #170994 is a reply to message #170992] Tue, 14 December 2010 13:08 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 12/14/2010 12:44 AM, Jeremy J Starcher wrote:
> On Mon, 13 Dec 2010 23:59:39 -0500, Jerry Stuckle wrote:
>
>> On 12/13/2010 10:26 PM, Adam Harvey wrote:
>>> On Mon, 13 Dec 2010 14:14:01 -0500, Jerry Stuckle wrote:
>>>> FreeBSD is a version of Linux.
>>>
>>> No, it's not.
>>>
>>> Adam
>>
>> I would suggest you learn what you're talking about. FreeBSD may have
>> been developed separately, but it is as much a Unix clone as Linux is,
>> and is generally considered in the same vein as other Linux versions.
>
> Actually, FreeBSD might be more of a Unix clone than Linux is, but ...
>
> that does not make it a version of Linux. It makes it a Unix-like OS.
>
> * FreeBSD does not run the Linux kernel (which is the only part of
> Linux that actually is Linux)
> * It is not byte-code compatible with Linux.
> * It is not 100% source compatible with Linux.
>

Sigh... I was afraid this would bring out the FreeBSD bigots...

The truth is the differences between FreeBSD and Linux are pretty minor,
especially in the administration. For all intent purposes, the vast
majority of Unix/Linux users consider FreeBSD to be close enough to
Linux that both are considered Unix-like clones. Only a few people feel
the need to make a big thing about minor differences.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Having trouble writing/copying/renaming file to sub-directory [message #170997 is a reply to message #170994] Tue, 14 December 2010 14:17 Go to previous message
Jeremy J Starcher is currently offline  Jeremy J Starcher
Messages: 5
Registered: December 2010
Karma: 0
Junior Member
On Tue, 14 Dec 2010 08:08:01 -0500, Jerry Stuckle wrote:
> Sigh... I was afraid this would bring out the FreeBSD bigots...
>
> The truth is the differences between FreeBSD and Linux are pretty minor,
> especially in the administration. For all intent purposes, the vast
> majority of Unix/Linux users consider FreeBSD to be close enough to
> Linux that both are considered Unix-like clones. Only a few people feel
> the need to make a big thing about minor differences.

Since we are way off topic here, this will be my last post on this
subject.

I'm not a FreeBSD bigot -- in fact, I don't believe I have ever used it.
I didn't make the post to be a bigot, but rather because I am a precise
man who goes out of my way to say what I mean.

As far as "The truth is the differences between FreeBSD and Linux are
pretty minor, especially in the administration."

That is so ... wrong. Heck, different Linux distros are administered
entirely differently. Just run Slack and Ubuntu side by side and see how
little two Linux distros have with themselves.

This whole thing is like saying "uint16 .. int32 ... they both pretty
much the same. They handle numbers and you can do math on them."
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: How to generate cryptographically-secure random big-integers?
Next Topic: PHP Guestbook list on PHPKode.com
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Nov 27 11:37:17 GMT 2024

Total time taken to generate the page: 0.02255 seconds