Page 1 of 1

Help needed in uploading file on server on a button click

Posted: Wed Jun 24, 2009 2:28 am
by shaam
Hi everyone,
I want to upload a file on server through button click on a web page,its working on my localhost but when i try to upload the file on server i get following error,


Warning: move_uploaded_file(Document/CV/0[1].578125001245226128_Services2.gif) [function.move-uploaded-file]: failed to open stream: Permission denied in /home/content/o/p/t/opt4me/html/uploadCV.php on line 21

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpEaJk81' to 'Document/CV/0[1].578125001245226128_Services2.gif' in /home/content/o/p/t/opt4me/html/uploadCV.php on line 21

My code is:

Code: Select all

 
<?php
include ('dbconnect.php');
$filename = $_FILES['userfile']['name'];
 
 
 
 
 
if($filename == '')
{
header('location: index.php');
}
else
{
 
$uploaddir = 'Document/CV/';
//chmod('777',$uploaddir);
$filename = $_FILES['userfile']['name'];
$fullfilename = $_FILES['userfile']['name'];
$uploadfile = $uploaddir.$fullfilename;
if(move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) 
{
$query2 = "insert into table1(CV_name,CV_fulname,date) values ('$filename','$fullfilename',curdate())";
mysql_query($query2);
$insertId2 = mysql_insert_id();
if($insertId2)
{
header('location:regester_user.php?cvid='.$insertId2);
exit;
} 
else
{
header('location: index.php');}
} 
//end code of Upload File.
}
 
 
?>

Re: Help needed in uploading file on server on a button clic

Posted: Mon Jun 29, 2009 11:45 am
by McInfo
Warning: move_uploaded_file(Document/CV/0[1].578125001245226128_Services2.gif) [function.move-uploaded-file]: failed to open stream: Permission denied in /home/content/o/p/t/opt4me/html/uploadCV.php on line 21
The problem is highlighted in red. The user under which PHP runs does not have permission to access the Document/CV directory. And, unless this user owns the directory, chmod() will be useless. By the way, a call to chmod() looks like this:

Code: Select all

chmod('path/to/file', 0777);
Edit: This post was recovered from search engine cache.