I am having a problem using PHP to upload files. Although it will create the directory it will not upload the file into it. the error message I get is "Warning: open_basedir restriction in effect. File is in wrong directory in /var/www/vhosts/itouch.com/httpdocs/uploadtest.php on line 28"
Any ideas? please find following code. Also safe mode is off
<?php
$name = "$myfile_name";
$folder = "$upload";
$tag = "http://www.itouch.com/support/desk/docs ... lder/$name";
define ("PATH", "/var/www/vhosts/itouch.com/httpdocs/support/desk/docs/user/",TRUE);
include('pageconnect.php');
$connection = @mysql_connect($host, $user, $pass) or die ("Unable to connect to database");
mysql_select_db($db) or die ("Unable to select database: $db ");
?>
<?php
echo "$tag";
?>
<?php
if($name != "") {
if(!$dir = @opendir(PATH.$folder))
mkdir(PATH.$folder,0777)
or die('Directory Could Not Be Created On Server.');
copy($myfile, PATH.$folder."/".$name)
or die('Could Not Copy File To Directory.');
mysql_query("INSERT INTO projdocs (job_id, doctype_id, tag, description, docdate, user_id)
VALUES ('$job_id', '$doctype_id', '$tag', '$description', '$today', '$user_id')")
or die('Can Not Preform Query!');
echo "$name Has Been Uploaded Successfully.";
}
else {
echo 'A File Must Be Selected To Upload.';
}
?>
problem uploading files
Moderator: General Moderators
Re: problem uploading files
I think the problem is with the BACK SLASH !lloydie-t wrote:I am having a problem using PHP to upload files. Although it will create the directory it will not upload the file into it. the error message I get is "Warning: open_basedir restriction in effect. File is in wrong directory in /var/www/vhosts/itouch.com/httpdocs/uploadtest.php on line 28"
Any ideas? please find following code. Also safe mode is off
<?php
$name = "$myfile_name";
$folder = "$upload";
$tag = "http://www.itouch.com/support/desk/docs ... lder/$name";
define ("PATH", "/var/www/vhosts/itouch.com/httpdocs/support/desk/docs/user/",TRUE);
include('pageconnect.php');
$connection = @mysql_connect($host, $user, $pass) or die ("Unable to connect to database");
mysql_select_db($db) or die ("Unable to select database: $db ");
?>
<?php
echo "$tag";
?>
<?php
if($name != "") {
if(!$dir = @opendir(PATH.$folder))
mkdir(PATH.$folder,0777)
or die('Directory Could Not Be Created On Server.');
copy($myfile, PATH.$folder."/".$name)
or die('Could Not Copy File To Directory.');
mysql_query("INSERT INTO projdocs (job_id, doctype_id, tag, description, docdate, user_id)
VALUES ('$job_id', '$doctype_id', '$tag', '$description', '$today', '$user_id')")
or die('Can Not Preform Query!');
echo "$name Has Been Uploaded Successfully.";
}
else {
echo 'A File Must Be Selected To Upload.';
}
?>
in line 28 :
copy($myfile, PATH.$folder."/".$name)
try this :
copy($myfile, PATH.$folder."//".$name)
since PHP cosiders (back slash / ) as an escape character
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
lloydie-t:
Have you tried commenting out the open_basedir directive in the php.ini file,
If you have a value set in there then all file operations are limited to the defined directory and below.
Mac
Have you tried commenting out the open_basedir directive in the php.ini file,
Code: Select all
;open_basedir =Mac
I decided to use move_uploaded_file instead of copy and is working OK except that I now have no permisions to delete uploaded files. Does anyone know how to change the file permisions when uploaded? please find the following code
<?php
if($name != "") {
if(!$dir = @opendir(PATH.$folder))
mkdir(PATH.$folder,0777)
or die('Directory Could Not Be Created On Server.');
move_uploaded_file($myfile, PATH.$folder."/".$name)
or die('Could Not Copy File To Directory.');
mysql_query("INSERT INTO projdocs (job_id, doctype_id, tag, description, docdate, user_id)
VALUES ('$job_id', '$doctype_id', '$tag', '$description', '$today', '$user_id')")
or die('Can Not Preform Query!');
echo "$name has been uploaded successfully.";
}
else {
echo 'A File Must Be Selected To Upload.';
}
?>
<?php
if($name != "") {
if(!$dir = @opendir(PATH.$folder))
mkdir(PATH.$folder,0777)
or die('Directory Could Not Be Created On Server.');
move_uploaded_file($myfile, PATH.$folder."/".$name)
or die('Could Not Copy File To Directory.');
mysql_query("INSERT INTO projdocs (job_id, doctype_id, tag, description, docdate, user_id)
VALUES ('$job_id', '$doctype_id', '$tag', '$description', '$today', '$user_id')")
or die('Can Not Preform Query!');
echo "$name has been uploaded successfully.";
}
else {
echo 'A File Must Be Selected To Upload.';
}
?>
Dont worry chaps. All sorted now.
<?php
if($name != "") {
if(!$dir = @opendir(PATH.$folder))
mkdir(PATH.$folder,0777)
or die('Directory Could Not Be Created On Server.');
move_uploaded_file($myfile, PATH.$folder."/".$name)
or die('Could Not Copy File To Directory.');
chmod(PATH.$folder."/".$name, 0755);
mysql_query("INSERT INTO projdocs (job_id, doctype_id, tag, description, docdate, user_id)
VALUES ('$job_id', '$doctype_id', '$tag', '$description', '$today', '$user_id')")
or die('Can Not Preform Query!');
echo "$name has been uploaded successfully.";
}
else {
echo 'A File Must Be Selected To Upload.';
}
?>
<?php
if($name != "") {
if(!$dir = @opendir(PATH.$folder))
mkdir(PATH.$folder,0777)
or die('Directory Could Not Be Created On Server.');
move_uploaded_file($myfile, PATH.$folder."/".$name)
or die('Could Not Copy File To Directory.');
chmod(PATH.$folder."/".$name, 0755);
mysql_query("INSERT INTO projdocs (job_id, doctype_id, tag, description, docdate, user_id)
VALUES ('$job_id', '$doctype_id', '$tag', '$description', '$today', '$user_id')")
or die('Can Not Preform Query!');
echo "$name has been uploaded successfully.";
}
else {
echo 'A File Must Be Selected To Upload.';
}
?>