Help needed in uploading file on server on a button click

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
shaam
Forum Newbie
Posts: 20
Joined: Tue Jun 23, 2009 6:36 am

Help needed in uploading file on server on a button click

Post 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.
}
 
 
?>
Last edited by Benjamin on Wed Jun 24, 2009 10:37 am, edited 1 time in total.
Reason: Added [code=php] tags.
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

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

Post 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.
Post Reply