Can';在移动到web服务器后,不要读取或上传php中的文件名
我试图用php上传一个文件,我在本地主机上创建的代码在我的机器上运行良好,但是,上传到web服务器后,它看到表单上的文件名为空,甚至不读取它。 这是我创建的代码。它将上传的文件名读取为空。请帮忙Can';在移动到web服务器后,不要读取或上传php中的文件名,php,Php,我试图用php上传一个文件,我在本地主机上创建的代码在我的机器上运行良好,但是,上传到web服务器后,它看到表单上的文件名为空,甚至不读取它。 这是我创建的代码。它将上传的文件名读取为空。请帮忙 <form action="registerSchool.php" method="post" enctype="multipart/form-data" name="form1"> <input type="text" name="schoolNam
<form action="registerSchool.php" method="post" enctype="multipart/form-data" name="form1">
<input type="text" name="schoolName" id="name" placeholder="Name of School" />
<input type="text" name="schoolAddr" id="Address" placeholder="School Address" />
<input type="text" name="schooluri" id="uri" placeholder="School Home Page URL" />
<label for="logo">Upload School logo: </label><input name="logo" type="file" id="logo" />
<input type="text" name="superAdminUser" id="Admin_username" placeholder="Super Admin UserName" />
<input type="password" name="superAdminPass" id="Admin_Password" placeholder="Super Admin Password" />
<input type="password" name="superAdminPass2" placeholder="Enter Password Again" />
<input type="submit" name="Submit" class="button button-small align_right" value="Create Institution" /><td>
</form>
<?php
session_start();
// create short variable names
$schoolName = $_POST['schoolName'];
$schoolAddr = $_POST['schoolAddr'];
$schooluri = $_POST['schooluri'];
$superAdminUser = $_POST['superAdminUser'];
$superAdminPass = $_POST['superAdminPass'];
$superAdminPass2 = $_POST['superAdminPass2'];
$logo = mysql_real_escape_string($_FILES['logo']['name']);
//This is the directory where images will be saved
$target = "resources/";
$target = $target . basename( $_FILES['logo']['name']);
//check if the fields are filled
if(empty($schoolName) || empty($schoolAddr) || empty($superAdminUser) || empty($superAdminPass) || empty($superAdminPass2) || empty($schooluri))
{
//redirect
header('Location: RegisterNewSchool.php?failure=1');
die;
}
if(empty($logo))
{
//redirect
header('Location: RegisterNewSchool.php?failure4=1');
die;
}
//check if admin passwords match
if($superAdminPass != $superAdminPass2)
{
//redirect
header('Location: RegisterNewSchool.php?failure1=1');
die;
}
if(!get_magic_quotes_gpc())
{
$schoolName = mysql_real_escape_string($schoolName);
$schoolAddr = mysql_real_escape_string($schoolAddr);
$schooluri = mysql_real_escape_string($schooluri);
$superAdminUser = mysql_real_escape_string($superAdminUser);
$superAdminPass = mysql_real_escape_string($superAdminPass);
$superAdminPass2 = mysql_real_escape_string($superAdminPass2);
}
//verify if logo is cool
if($_FILES["logo"]["size"] < 500000) {
//verify if logo has uploaded to server
if(move_uploaded_file($_FILES['logo']['tmp_name'], $target)){
//connect to the database
include('dbconnect.php');
//query the database
$query5 = "CREATE TABLE studentDetails
( student_id int(11) not null auto_increment primary key,
registration_number char(50) not null,
surname char(200),
othernames char(200),
student_pass char(50)
)";
$query = "CREATE TABLE schoolDetails
( school_id int(11) not null auto_increment primary key,
school_name char(50) not null,
school_addr char(200),
schooluri char(150),
school_logo varchar(50)
)";
$query2 = "CREATE TABLE adminDetails( admin_id int(11) not null auto_increment primary key,
admin_type char(20) not null,
admin_name char(50),
admin_pass char(50)
)";
$query3 = "INSERT INTO schoolDetails(school_name,school_addr,schooluri,school_logo)
VALUES('".$schoolName."','".$schoolAddr."','".$schooluri."','".$logo."')";
$query4 = "INSERT INTO adminDetails(admin_type,admin_name,admin_pass)
VALUES('super','".$superAdminUser."','".$superAdminPass."')";
$result = $db->query($query);
$result2 = $db->query($query2);
$result3 = $db->query($query3);
$result4 = $db->query($query4);
$result5 = $db->query($query5);
if ($result5) {
echo 'query success';
} else {
echo 'An error occurred. '. mysqli_error($db);
}
//disconnect from the database
include('dbdisconnect.php');
//redirect
$_SESSION['valid_admin'] = $superAdminUser;
header('Location: AdminPanel.php?success=1');
die;
}
else {
//redirect
header('Location: RegisterNewSchool.php?failure2=1');
die;
}
}
else {
//redirect
header('Location: RegisterNewSchool.php?failure3=1');
die;
}
上传学校标志:
您有在服务器上写入的权限吗?可能您只需要对文件夹进行chmod
我想您的代码应该可以工作在控制台中尝试chmod-R 777。但要注意安全。仅对上载目录使用此命令。谢谢,该目录的默认权限为755,更改为777时,将在我的web浏览器中返回“未找到页面”。我不明白您何时收到此消息?当你上传文件时?请注意,上面的脚本在if(empty($logo)){//redirect头('Location:RegisterNewSchool.php?failure4=1');die;}处重定向。它根本没有试图上传,每当我尝试上传时,它都返回一个空文件名,表现为我没有选择上传文件。