Page 1 of 1

failed to open stream: Permission denied

Posted: Mon Mar 05, 2007 6:00 am
by tolearn
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi,

Im trying to upload a document file in to a remote server. But im getting the following error. I tried changing the permission for the folder also.

It works fine when i tried in the local machine. What may be the problem

Warning: move_uploaded_file(/home/smartchu/public_html/website_content/test1_595446942/test.doc): failed to open stream: Permission denied in /home/smartchu/public_html/upload_test.php on line 26

Warning: move_uploaded_file(): Unable to move '/tmp/php23ki2U' to '/home/smartchu/public_html/website_content/test1_595446942/test.doc' in /home/smartchu/public_html/upload_test.php on line 26

Code: Select all

$id=$nam."_".rand();
$uploaddir="/home/smartchu/public_html/website_content/".$id."/";
$name1 = $_FILES["userfile1"]["name"];
$destination1 = $uploaddir.$name1;
$destination1 = "/home/smartchu/public_html/website_content/".$name1;
move_uploaded_file($_FILES['userfile1']['tmp_name'], $destination1);//line #26

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Mon Mar 05, 2007 6:19 am
by volka
$id=$nam."_".rand();
$uploaddir="/home/smartchu/public_html/website_content/".$id."/";
A random directory name? What are the bets on this directory really exists?
move_uploaded_file() does not create (missing) directories.

Posted: Mon Mar 05, 2007 6:31 am
by Kieran Huggins
also touch() the file first, for some reason it helps half the time

failed to open stream: Permission denied

Posted: Mon Mar 05, 2007 11:12 pm
by tolearn
I tried without creating a directory also. I tried to upload the file directly . But getting the same error

Posted: Tue Mar 06, 2007 12:54 am
by volka
And you new code is ....? Does it contain debug code like echo...file_exists...is_readable and so on? If not, why not?

Posted: Tue Mar 06, 2007 6:02 am
by tolearn
I tried with file exists() it gives file not exists error.

But i tried the same code uploading in locan server and it works perfectly.

Posted: Tue Mar 06, 2007 6:12 am
by volka
try

Code: Select all

<?php
error_reporting(E_ALL); ini_set('display_errors', true);

function checkpath($p) {
	$path = '';
	echo '<fieldset><legend>', htmlentities($p), "</legend>\n";
	foreach( array_filter(explode('/', $p)) as $d) {
		$path .= '/'.$d;
		echo $path,' ',
			is_file($path) ? 'f':'-',
			is_dir($path) ? 'd':'-',
			is_readable($path) ? 'r':'-',
			is_writable($path) ? 'w':'-',
			is_executable($path) ? 'x':'-',
			"<br />\n";
	}
	echo "</fieldset>\n";
}

$id=$nam."_".rand();
$uploaddir="/home/smartchu/public_html/website_content/".$id."/";
$name1 = $_FILES["userfile1"]["name"];
$destination1 = $uploaddir.$name1;
$destination1 = "/home/smartchu/public_html/website_content/".$name1;

checkpath($_FILES['userfile1']['tmp_name']);
checkpath($destination1);
move_uploaded_file($_FILES['userfile1']['tmp_name'], $destination1);//line #26 

?>
What does it print?

Posted: Wed Mar 07, 2007 3:06 am
by tolearn
I got the output as follows:

/tmp/php7AbDG5/tmp -drwx
/tmp/php7AbDG5 f-rw-
/home/smartchu/public_html/website_content/Taj_tender_request.doc/home -----
/home/smartchu -dr-x
/home/smartchu/public_html -drwx
/home/smartchu/public_html/website_content -dr--
/home/smartchu/public_html/website_content/Taj_tender_request.doc
Warning: is_file(): Stat failed for /home/smartchu/public_html/website_content/Taj_tender_request.doc (errno=13 - Permission denied) in /home/smartchu/public_html/dev_test.php on line 10
-
Warning: is_dir(): Stat failed for /home/smartchu/public_html/website_content/Taj_tender_request.doc (errno=13 - Permission denied) in /home/smartchu/public_html/dev_test.php on line 11
----

Posted: Wed Mar 07, 2007 3:17 am
by volka
tolearn wrote:/home/smartchu/public_html/website_content -dr--
Your script is not allowed to change to or write to the directory /home/smartchu/public_html/website_content thus it cannot create /home/smartchu/public_html/website_content/Taj_tender_request.doc

perhaps the output of

Code: Select all

<?php
$cmds = array(
		'who am i',
		'whoami',
		'groups',
		'ls -lad  /home/smartchu/public_html/website_content/'
	);
foreach($cmds as $command) {
	echo '<div>', $command, ': ';
	system($command);
	echo "</div>\n";
}
can shed some light on the problem.

Posted: Wed Mar 07, 2007 11:41 pm
by tolearn
Getting output lke this

who am i:
whoami: nobody
groups: nobody
ls -lad /home/smartchu/public_html/website_content/: drwxr--r-- 2 smartchu smartchu 4096 Feb 27 04:01 /home/smartchu/public_html/website_content/

Posted: Thu Mar 08, 2007 1:06 am
by volka
drwxr--r-- 2 smartchu smartchu 4096 Feb 27 04:01 /home/smartchu/public_html/website_content/
the d at the beginning means it's a directory. The next three, green characters mean the owner has read,write,execute permissons. The blue section shows the permissions for the group: read-only. And the red section shows the permissions granted to everybody else (not the owner and not in "owning" group)
The next green text is the name of the owner: smartchu. And there's also a group called smartchu and it's the group associated with this directory.
You script runs as nobody which is only member of the group nobody. So neither the owner nor the group permissions apply when accessing the directory /home/smartchu/public_html/website_content/
see also: http://www.google.de/search?hl=en&q=uni ... tnG=Search