Jump to content

Copying files using PHP


Gooner

Recommended Posts

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.
Link to comment
Share on other sites

[!--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) [snapback]370861[/snapback][/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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

[!--quoteo(post=370880:date=May 3 2006, 08:26 AM:name=craygo)--][div class=\'quotetop\']QUOTE(craygo @ May 3 2006, 08:26 AM) [snapback]370880[/snapback][/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.
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.