Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 09-30-2007, 12:35 PM copy() issue
Novice Talker

Posts: 10
Trades: 0
Hello!

the code below echoes "error". What am I doing wrong?

PHP Code:
mkdir("copy"0777);
$ret_val copy("test.txt""copy");
echo ( 
$ret_val "success" "error" ); 
Also tried this and it's the same:

PHP Code:
mkdir("copy"0777);
$ret_val copy("test.txt""copy/test.txt");
echo ( 
$ret_val "success" "error" ); 
But if I want to make a copy of test.txt in the same directory, this goes fine.

Is there any function to move a file in another directory?
Thanks
funky86 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-30-2007, 01:32 PM Re: copy() issue
coolkbk585's Avatar
Be good this Christmas!

Latest Blog Post:
KBlog has been deativated
Posts: 642
Name: Kyle
Location: Ada, MI
Trades: 0
PHP Code:
mkdir("copy"0777);
$ret_val copy("test.txt"".copy/test.txt");
echo ( 
$ret_val "success" "error" ); 
Try that code. I added a period in front of the subfolder 'copy'. PHP needs to have that period there.
__________________
<?php if($Adsense_Revenue > 0): define('HAPPINES','100%'); else: define('HAPPINESS', '0%') endif; ?>
coolkbk585 is offline
Reply With Quote
View Public Profile Visit coolkbk585's homepage!
 
Old 09-30-2007, 01:39 PM Re: copy() issue
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
PHP Code:
mkdir("copy"0777);
if(
file_exists("test.txt") && @chmod("test.txt"0777) && is_writable("copy/")){
$ret_val = @copy("test.txt""copy/test.txt");
echo ( 
$ret_val "success" "error" );  

You may want to put from check in there, and try chmodding it. also using '@' will tell PHP weather it worked or not.

Also, is any error code coming up? it could be that your not making copy/ directory writable. Another thing, you may need to make the file local to the server, for example '/home/files/copy/'
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE

Last edited by rogem002; 09-30-2007 at 01:42 PM..
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 09-30-2007, 02:57 PM Re: copy() issue
Novice Talker

Posts: 10
Trades: 0
coolkbk585's advise also echoes "error", rogem002's code didn't echo anything. I also tried with the whole path to the new file (including the home or root folder).

I tried to create the folder by my self with the FTP client and set the permition to 777. Then I got success and the file was copied succesfully.

Interesting is that if I set the folder permition while creating the directory; mkdir("copy", 0777) - the permition actually isn't 777 but 755. So I tried to separate this process and executed:

PHP Code:
mkdir("copy");
chmod("copy"0777);
$ret_val copy("test.txt""copy/test.txt");
echo ( 
$ret_val "success" "error" ); 
Permition actually was 777 but I still got the error and the file wasn't copied .

Per FTP client created folder, the argument "user" in properties has value 6267 but programicaly created folder has 99 in the "user" argument. Maybe this could be the reason?
funky86 is offline
Reply With Quote
View Public Profile
 
Old 09-30-2007, 04:52 PM Re: copy() issue
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
You may first need to allow permissions in the parent directory you are running the script from to allow php to create and write to the directory.
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 10-01-2007, 10:27 AM Re: copy() issue
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
Try:

PHP Code:
mkdir("copy"0777);
if(
file_exists("test.txt") && @chmod("test.txt"0777) && is_writable("copy/")){
$ret_val = @copy("test.txt""copy/test.txt");
echo ( 
$ret_val "success" "error" );  
} else {
echo 
"error is either: file does not exist. the file/folder is not writable.";

__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 10-01-2007, 02:17 PM Re: copy() issue
Novice Talker

Posts: 10
Trades: 0
The permission of the parent directory is set to 777 (the directory in which is the script). Also the parent directory was created per FTP client so the user is 6267.

rogem002's code echoes this:"error is either: file does not exist. the file/folder is not writable." and the created folder "copy" has permission set to 755.

!

Thanks for helping me guys!

Last edited by funky86; 10-01-2007 at 02:21 PM..
funky86 is offline
Reply With Quote
View Public Profile
 
Old 10-01-2007, 06:15 PM Re: copy() issue
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Sorry to butt in here, but i just want to ask something, why is it on the thousands of PHP install scripts out there why do they always ask you to manually cmodd files/folders to writable why dont the script automatically cmodd it to the correct permission and even cmodd it back at the end is there any real reason?

I would like to know if there is a reason not to, as i am writible my own install scripts and stuff.

Thanks,
sorry to butt in again
Dan
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 10-01-2007, 08:06 PM Re: copy() issue
Defies a Status

Posts: 1,606
Trades: 0
Some servers are configged so that the mkdir function can not create a directory with permissions greater than 644 or whatever value is set by sysadmin.

The soultion is to mkdir $newdir; and then on the next line
chmod $newdir 777;

and then continue your script.
__________________
Colbyt

Please login or register to view this content. Registration is FREE
colbyt is offline
Reply With Quote
View Public Profile
 
Old 10-02-2007, 03:37 AM Re: copy() issue
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
Quote:
Originally Posted by colbyt View Post
Some servers are configged so that the mkdir function can not create a directory with permissions greater than 644 or whatever value is set by sysadmin.

The soultion is to mkdir $newdir; and then on the next line
chmod $newdir 777;

and then continue your script.
You don't need 777 on a directory if you are going to put files there by your script and then read them by apache. 755 will be quite enough in this case.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 10-02-2007, 03:48 AM Re: copy() issue
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
Quote:
Originally Posted by dansgalaxy View Post
Sorry to butt in here, but i just want to ask something, why is it on the thousands of PHP install scripts out there why do they always ask you to manually cmodd files/folders to writable why dont the script automatically cmodd it to the correct permission and even cmodd it back at the end is there any real reason?

I would like to know if there is a reason not to, as i am writible my own install scripts and stuff.

Thanks,
sorry to butt in again
Dan
This happens because usually user who uploads the script and user who runs apache (I mean user ID in linux system on the server) are different and thus the php script which is started from apache simply cannot write to folder which is owned by another user. Also usually apache user does not belong to the same group as script owner, that's why setting group write permission also does not give effect. Thus the only way to write to folder from the script is setting directory world writable. But considering security reasons it is not recommended to leave directory world writable, especially if nobody is expected to write there.

If a system is configured in such a way that all users are in same group with apache user and newly created dirs permissions are 775 then you will not have to chmod the dir manually to write there from the script, but you will have to chmod it AFTER to prevent other users' scripts to write here. So in general case there is no way to avoid manual chmodding at all.

Well, it is, but only if you are not going to write to the filesystem from the script at all.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 10-02-2007, 05:36 AM Re: copy() issue
Defies a Status

Posts: 1,606
Trades: 0
Quote:
Per FTP client created folder, the argument "user" in properties has value 6267 but programicaly created folder has 99 in the "user" argument. Maybe this could be the reason?
I missed this post the first time through. Sorry I repeated what you said you already tried.

Yes I think it can. I don't know enough of the detail to be specific. You may want to investigate the change owner function (chown, I think). It may hold the key to what you are trying to do.
__________________
Colbyt

Please login or register to view this content. Registration is FREE
colbyt is offline
Reply With Quote
View Public Profile
 
Old 10-04-2007, 10:29 AM Re: copy() issue
Novice Talker

Posts: 10
Trades: 0
No problem colbyt.

chown() also didn't solve my problem. Only the superuser can use it.

I mailed the server administrator and got the explanation that a folder created per a php scipt has nouser/nogroup privilegion and that's why writing isn't possible in such a directory. That's because the safe-mode is turned on (on the server) and I should get more information on this link: http://si2.php.net/manual/en/features.safe-mode.php.

Well ... I'll find more information about how to write into a php script created folder while safe-mode is turned on. But if someone could give me any advices from the first hand about this, I'll appritiate it.

Thanks to all!
funky86 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to copy() issue
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.44496 seconds with 12 queries