homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

upload file to server

 4:02 pm on Mar 2, 2009 (gmt 0)

Hello. I found out the dir by echo "getcwd()". But at the end the page shows mistake , warning Warning: move_uploaded_file(/home/example/public_html/baze/pask varzyb.xls) [function.move-uploaded-file]: failed to open stream: Permission denied in /home/example/public_html/baze/failas.php on line 23

thanks for any ideas.

<center>upload file</center>
select file.
<form method="POST" enctype="multipart/form-data">
<input type="file" name="file1" size="30">
<input type="submit" value="send" name="click">
$uploaddir = '/home/example/public_html/baze/';
$uploadfile = $uploaddir . basename($_FILES['file1']['name']);
echo getcwd();

[edited by: dreamcatcher at 11:31 pm (utc) on Mar. 9, 2009]
[edit reason] Exemplified server path. [/edit]



 5:19 pm on Mar 2, 2009 (gmt 0)

It means that the directory baze does not have permissions to be written to. Chmod 655 first, if it doesn't work, chmod 777.


 5:36 pm on Mar 2, 2009 (gmt 0)

I wrote chmod($uploaddir,655); and i got reply Warning: chmod() [function.chmod]: Operation not permitted in /home/birzai12/public_html/baze/failas.php on line 21


 12:12 am on Mar 3, 2009 (gmt 0)

Okay, I'm speaking a little out of turn here and may be incorrect. (where's jdMorgan when you need him . . . )

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.


 11:45 am on Mar 8, 2009 (gmt 0)

Thanks a lot, Rocknbil. You helped very much. I solved this problem.

Oliver Henniges

 9:00 pm on Mar 9, 2009 (gmt 0)

I hope the code snippet you gave is a simplified extract, specifically created for this forum?

You are NOT going to upload excel-files to your (public?) directory without verifying its content, are you?

In particular after posting your cgi-path here in public...

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved