Jump to content


Photo

Copying files using PHP


  • Please log in to reply
5 replies to this topic

#1 Gooner

Gooner
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 03 May 2006 - 11:02 AM

Hi

I have recently changed web hosting from a local compnay to a VPS system (linux based).

Everything is still working fine with my site, except one thing.

I use a page on my site to upload PDF files into a directory (these pdf files can then be accessed via a browser). This was working fine on my old server, but now there seems to be an issue with files that already exist.

If I upload a file called hello.pdf and there is already a file called hello.pdf in that directory, I want it to overwrite the original file (like it did on the old server). The trouble is, it won't overwrite them.

If I upload a file that doesn't already exist, it uploads fine (yes, I have write permissions on the directory). If I then try to overwrite THIS file, again, it works fine.

The trouble is when I try to overwtite a pdf file that was moved from the old server.

The new files I upload have an owner and group both set as "apache". The existing files have a different user and group, which I think is what is causing the problem.

Can anyone suggest a way I can get round this? I'd rather not delete and re-upload all the PDF files, as there are too many. Is there a way of "batch changing" all of the owner/group details within a directory, or is there a way in PHP that I can force it to overwrite the existing files that belong to a different user/group.

Any help really appreciated.

Thanks.

#2 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 03 May 2006 - 12:20 PM

It sounds like the only way around this is to modify the permissions on all of those files. I don't think deleting them and re-uploading them is going to help.

Info: PHP Manual


#3 umasankar

umasankar
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 03 May 2006 - 12:38 PM

Hi,

If you are using a Linux server, The Problem is File permission Only..

Change that folder permission as 777.



#4 Gooner

Gooner
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 03 May 2006 - 01:14 PM

[!--quoteo(post=370861:date=May 3 2006, 07:38 AM:name=Umasankar Subramanian)--][div class=\'quotetop\']QUOTE(Umasankar Subramanian @ May 3 2006, 07:38 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Hi,

If you are using a Linux server, The Problem is File permission Only..

Change that folder permission as 777.
[/quote]

It IS a Linux server (VPS), running Fedora, and the folder where the PDF files are contained HAS a setting of 777.

The problem remains however..... I can overwrite files uploaded by my script (owner = apache), but files that were FTP'd into the directory won't overwrite (owner = user).

Thanks for your time

#5 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 03 May 2006 - 01:26 PM

if you set the permissions on the folder, it will not make all the files under it the same. The new files you ad are getting the new permission, but the existing ones are not. You have to do a recursive chmod to make sure all the files and folders in the directory get the permissions. If you are trying to do this thru your FTP client, you will have to make sure you click all files and folder if your client even has that option. If you are doing it thru ssh then you have to use -R(make sure it is capital) to make all the files and folders that permission.

Ray

#6 Gooner

Gooner
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 03 May 2006 - 02:06 PM

[!--quoteo(post=370880:date=May 3 2006, 08:26 AM:name=craygo)--][div class=\'quotetop\']QUOTE(craygo @ May 3 2006, 08:26 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
if you set the permissions on the folder, it will not make all the files under it the same. The new files you ad are getting the new permission, but the existing ones are not. You have to do a recursive chmod to make sure all the files and folders in the directory get the permissions. If you are trying to do this thru your FTP client, you will have to make sure you click all files and folder if your client even has that option. If you are doing it thru ssh then you have to use -R(make sure it is capital) to make all the files and folders that permission.

Ray
[/quote]


Thanks Ray

I use SecureFX as an FTP client.

I select all the files in the directory as you stated, and changed them all to 777. It did them all, EXCEPT one PDF that was uploaded via the script I wrote. This file owner is apache (group = apache), whereas the rest have the owner user1.

I deleted all the PDF files in the directory, changed the directory to 777 and re-uploaded them. All files were now 777. (same outcome as above). I now used my PHP script to upload a NEW file into this directory, but when I checked the permissions on this NEW file, they read 644 - even though the directory is set to 777.

Any ideas why this is happening?

Thanks again.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users