Forum Moderators: coopster
thanks for any ideas.
<html>
<body>
<center>upload file</center>
<br>
<br>
select file.
<br>
<form method="POST" enctype="multipart/form-data">
<input type="file" name="file1" size="30">
<input type="submit" value="send" name="click">
</form>
<br>
<br>
<?php
if(isset($_POST['click']))
{
$uploaddir = '/home/example/public_html/baze/';
$uploadfile = $uploaddir . basename($_FILES['file1']['name']);
print_r($_FILES);
echo getcwd();
move_uploaded_file($_FILES['file1']['tmp_name'],$uploadfile);
}
?>
</body>
</html>
</body>
</html>
[edited by: dreamcatcher at 11:31 pm (utc) on Mar. 9, 2009]
[edit reason] Exemplified server path. [/edit]
This is probably a related issue, one of ownership. If you uploaded and created this directory via ftp, the owner is you, which is your user name for FTP. When your script goes to change mode on a file, it's doing so as the user Apache. So Apache can't change permissions on a file owned by you.
The solutions: have your script write the directory, it will then be owned by Apache. Not as difficult as it sounds, and is good programming practice to check for any resource before trying to write to it. Pseudo-code would be something like
if (-d $directory) { // -d = is a directory
.... do something in $directory
}
else {
system(`mkdir $directory 655`);
... do something in $directory
}
Once run the first time, it will never use that "else" again.
Another thing you can do is SSH in, sudo su which makes you "pseudo-root" and set permissions. Granted, the directory is now owned by root, so you might want to also chown to Apache or neither the script or you as an FTP user can do anything but delete it.
Again, I'm a little gray on system issues but using one of the above usually gets you to a point where you can write safely to a directory.