当我执行以下代码时,它显示错误
Warning: copy() [function.copy]: open_basedir restriction in effect. File() is not within the allowed path(s): (/home/:/usr/lib/php:/tmp:/www/) in /home/a3629462/public_html/PhpProject2ad post/post forward.php on line 20
线20以下给出
if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path))
完整代码如下所示
$file_name = $HTTP_POST_FILES['ufile']['name'];
$random_digit= md5(rand() * time());
$new_file_name=$random_digit.$file_name;
$path= "upload/".$new_file_name;
if($ufile !=none)
{
if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path))
{
echo "Successful<BR/>";
echo "File Name :".$new_file_name."<BR/>";
echo "File Size :".$HTTP_POST_FILES['ufile']['size']."<BR/>";
echo "File Type :".$HTTP_POST_FILES['ufile']['type']."<BR/>";
}else{
echo "Error";
}
}
?>
<?php
$file_name1 = $HTTP_POST_FILES['ufile1']['name'];
$random_digit1= md5(rand() * time());
$new_file_name1=$random_digit1.$file_name1;
$path1= "upload/".$new_file_name1;
if($ufile1 !=none)
{
if(copy($HTTP_POST_FILES['ufile1']['tmp_name'], $path1))
{
echo "Successful<BR/>";
echo "File Name :".$new_file_name1."<BR/>";
echo "File Size :".$HTTP_POST_FILES['ufile1']['size']."<BR/>";
echo "File Type :".$HTTP_POST_FILES['ufile1']['type']."<BR/>";
}else{
echo "Error";
}
}
?>
<?php
$file_name2 = $HTTP_POST_FILES['ufile2']['name'];
$random_digit2= md5(rand() * time());
$new_file_name2=$random_digit2.$file_name2;
$path2= "upload/".$new_file_name2;
if($ufile2 !=none)
{
if(copy($HTTP_POST_FILES['ufile2']['tmp_name'], $path2))
{
echo "Successful<BR/>";
echo "File Name :".$new_file_name2."<BR/>";
echo "File Size :".$HTTP_POST_FILES['ufile2']['size']."<BR/>";
echo "File Type :".$HTTP_POST_FILES['ufile2']['type']."<BR/>";
}else{
echo "Error";
}
}
?>
$file_name3 = $HTTP_POST_FILES['ufile3']['name'];
$random_digit3= md5(rand() * time());
$new_file_name3=$random_digit3.$file_name3;
$path3= "upload/".$new_file_name3;
if($ufile3 !=none)
{
if(copy($HTTP_POST_FILES['ufile3']['tmp_name'], $path3)){
echo "Successful<BR/>";
echo "File Name :".$new_file_name3."<BR/>";
echo "File Size :".$HTTP_POST_FILES['ufile3']['size']."<BR/>";
echo "File Type :".$HTTP_POST_FILES['ufile3']['type']."<BR/>";
}else{
echo "Error";
}
}
?>
<?php
$file_name4 = $HTTP_POST_FILES['ufile4']['name'];
$random_digit4= md5(rand() * time());
$new_file_name4=$random_digit4.$file_name4;
$path4= "upload/".$new_file_name4;
if($ufile4 !=none)
{
if(copy($HTTP_POST_FILES['ufile4']['tmp_name'], $path4))
{
echo "Successful<BR/>";
echo "File Name :".$new_file_name4."<BR/>";
echo "File Size :".$HTTP_POST_FILES['ufile4']['size']."<BR/>";
echo "File Type :".$HTTP_POST_FILES['ufile4']['type']."<BR/>";
}else{
echo "Error";
}
}
?>
<?php
$host=""; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl_name=""; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// get data that sent from form
$topic=$_POST['topic'];
$detail=$_POST['detail'];
$name=$_POST['name'];
$email=$_POST['email'];
$test=$_POST['test'];
$datetime=date("d/m/y h:i:s"); //create date time
$sql="INSERT INTO $tbl_name(topic, detail, name, email, ufile, ufile1, ufile2, ufile3, ufile4, test, datetime)VALUES('$topic', '$detail', '$name', '$email', '$new_file_name', '$new_file_name1', '$new_file_name2', '$new_file_name3', '$new_file_name4', '$test', '$datetime')";
$result=mysql_query($sql);
if($result){
echo "Successful<BR>";
echo "<a href=listofpost.php>View your topic</a>";
}
else {
echo "ERROR";
}
mysql_close();
?>
</body>
</html>
我需要相同的代码我使用的如何更改错误上面的代码我试图上传4个图像文件重命名并保存路径到SQL并保存5个输入文本SQL数据库
Warning: copy() [function.copy]: open_basedir restriction in effect. File() is not within the allowed path(s): (/home/:/usr/lib/php:/tmp:/www/) in /home/a3629462/public_html/PhpProject2ad post/post forward.php on line 20
Warning: copy() [function.copy]: open_basedir restriction in effect. File() is not within the allowed path(s): (/home/:/usr/lib/php:/tmp:/www/) in /home/a3629462/public_html/PhpProject2ad post/post forward.php on line 39
Warning: copy() [function.copy]: open_basedir restriction in effect. File() is not within the allowed path(s): (/home/:/usr/lib/php:/tmp:/www/) in /home/a3629462/public_html/PhpProject2ad post/post forward.php on line 58
Warning: copy() [function.copy]: open_basedir restriction in effect. File() is not within the allowed path(s): (/home/:/usr/lib/php:/tmp:/www/) in /home/a3629462/public_html/PhpProject2ad post/post forward.php on line 77
Warning: copy() [function.copy]: open_basedir restriction in effect. File() is not within the allowed path(s): (/home/:/usr/lib/php:/tmp:/www/) in /home/a3629462/public_html/PhpProject2ad post/post forward.php on line 95
答案 0 :(得分:0)
您的文件夹路径存在问题。
使用$_SERVER['DOCUMENT_ROOT']
获取根路径并更新您的代码,如下所示。
$rootPath = $_SERVER['DOCUMENT_ROOT'];
$path= $rootPath."upload/".$new_file_name;
$path1= $rootPath."upload/".$new_file_name1;