This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > Dreamweaver > August 2004 > PHP Upload Overwrite files





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author PHP Upload Overwrite files
alwaysabitlost

2004-08-22, 11:14 pm

Hi guys

I want a user to be able to overwrite an image in a folder with a new one of
the same name when they upload it through a form. I get an error from PHP if I
try and do it at the moment as it's clearly already finding the file of that
name already exists and is not able to overwrite it.

Thanks

ZhongQiang

2004-08-23, 4:15 am

Well, i guess its not because of PHP thats causing the error, but your file
permission. Change it to chmod777 and it should be able to be writen over. =)

Originally posted by: alwaysabitlost
Hi guys

I want a user to be able to overwrite an image in a folder with a new one of
the same name when they upload it through a form. I get an error from PHP if I
try and do it at the moment as it's clearly already finding the file of that
name already exists and is not able to overwrite it.

Thanks



alwaysabitlost

2004-08-23, 7:16 pm

Hi

No the folder permissions are fine, if the file doesn't already exist in the directory it copies the image to it fine, it's just an overwrite problem replacing an image with the same name.
ZhongQiang

2004-08-23, 11:14 pm

how about the permission for the file you are overiting? by default, it doesnt
allow overiting by user/group, except admin. Using a PHP script means it
overwritten by user and not admin. Maybe you might wana try just that? do let
me know if there's still such an issue.

Originally posted by: alwaysabitlost
Hi

No the folder permissions are fine, if the file doesn't already exist in the
directory it copies the image to it fine, it's just an overwrite problem
replacing an image with the same name.



alwaysabitlost

2004-08-23, 11:15 pm

Hi

Yeah I thought you might have meant that, but I'm not sure how to alter the
settings?

I've decided to generate a new name for each file uploaded instead and just
update the database accordingly, but if you could let me know how to set image
permissions for future reference that would be great.

ZhongQiang

2004-08-24, 4:14 am

you could chmod your files to chmod777 or make use of .htaccess to do so.
however, you could also make use of the programming language that you are using
to set the permissions. however, if you would wana do so manually, you could
make use of ftp softwares to change the file permisions to 777 instead of the
default 644.

Originally posted by: alwaysabitlost
Hi

Yeah I thought you might have meant that, but I'm not sure how to alter the
settings?

I've decided to generate a new name for each file uploaded instead and just
update the database accordingly, but if you could let me know how to set image
permissions for future reference that would be great.



alwaysabitlost

2004-08-26, 12:17 pm

Brilliant, I found this on php.net

<?php
// Read and write for owner, nothing for everybody else
chmod("/somedir/somefile", 0600);

// Read and write for owner, read for everybody else
chmod("/somedir/somefile", 0644);

// Everything for owner, read and execute for others
chmod("/somedir/somefile", 0755);

// Everything for owner, read and execute for owner's group
chmod("/somedir/somefile", 0750);
?>

Thanks for you help

Sponsored Links


Copyright 2003 - 2009 forum4designers.com  Software forum  Computer Hardware reviews