我有一个本地开发的 PHP 页面,运行良好。将其上传到服务器后,我现在只得到一个空白的白屏?这是完全相同的代码,在本地工作正常,但在远程工作则不然。我已经尝试设置错误报告,但仍然没有给我任何错误,只是一个空白的白屏。
代码:
$firstname = $phone = $email = $picture = $sqlcon = "";
$firstnameErr = $phoneErr = $emailErr = $pictureErr = $sqlErr = $filterErr = "";
$statusmsg = "";
$newpicture = $registered = "false";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// If the user has not entered a firstname and has not entered details previously
if ((empty($_POST["firstname"])) && empty($_POST["hfirst"])) {
$firstnameErr = "Firstname is required for submission";
}
else {
if (!empty($_POST["firstname"])) {
$firstname = $_POST["firstname"];
}
else {
$firstname = $_POST["hfirst"];
}
if (!preg_match("/^[a-zA-Z ]*$/", $firstname)) {
$firstnameErr="Please ensure you have entered only characters for your first name";
}
}
// If the user has not entered a phone number and has not entered details previously
if ((empty($_POST["phone"])) && (empty($_POST["hphone"]))) {
$phoneErr = "Please ensure you have entered a phone number";
}
else {
if (!empty($_POST["phone"])) {
$phone = $_POST["phone"];
}
else {
$phone = $_POST["hphone"];
}
if (!is_numeric($phone)) {
$phoneErr = "Please ensure you have entered a valid phone number";
}
}
if ((empty($_POST["email"])) && (empty($_POST["hemail"]))) {
$emailErr = "Please ensure you have entered your email address";
}
else {
if (!empty($_POST["email"])) {
$email = $_POST["email"];
}
else {
$email = $_POST["hemail"];
}
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email)) {
$emailErr = "Please ensure you have entered a valid email address";
}
}
if ((empty($_FILES["file"]["name"])) && (empty($_POST["hfile"]))) {
$pictureErr = "Please ensure you have selected a picture to upload";
}
else {
if (!empty($_FILES["file"]["name"])) {
if ($_FILES["file"]["size"] > 1048576) {
$pictureErr = "The maximum size for a picture is 1mb";
}
else {
// Ensure the user has selected a file of accepted type
$temp = explode(".", $_FILES["file"]["name"]);
$ext = end($temp);
$allowedExt = array ("gif", "JPEG", "jpg", "png", "JPG");
if (!in_array($ext, $allowedExt)) {
$pictureErr = "Please ensure you have uploaded an image file";
}
}
$newpicture = "true";
$picture = $_FILES["file"]["name"];
}
else {
$picture = $_POST["hpicture"];
}
}
$sqlcon = mysqli_connect("localhost", "USER", "PASS", "personneldb");
if (mysqli_connect_errno()) {
$sqlErr = "Could not connect to database";
mysqli_close($sqlcon);
}
if ($newpicture == "true") {
if (!move_uploaded_file($_FILES["file"]["tmp_name"], "./upload/".$_FILES["file"]["name"])) {
$pictureErr = "File could not be uploaded";
}
}
if ((empty($firstnameErr)) && (empty($emailErr)) && (empty($phoneErr)) && (empty($pictureErr == "")) && (empty($sqlErr == ""))) {
mysqli_query($sqlcon, "INSERT INTO test2Details(Firstname, Phone, Email, ImageName)
VALUES ('$firstname', '$phone', '$email', '$picture')");
// Display status message
$statusmsg = "Success! Your details and picture have been uploaded and stored";
}
if ((!empty($firstname)) && (!empty($phone)) && (!empty($email)) && (!empty($picture))) {
$registered = "true";
}
else {
$registered = "false";
}
}
这将能够在您的服务器中显示错误,但请记住,不建议在生产中使用它,而不是在 PHP 文件中使用它,这些配置必须在 php.ini 中设置
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(-1);
欲了解更多信息,您可以查看:
- http://php.net/manual/en/function.error-reporting.php http://php.net/manual/en/function.error-reporting.php
- http://php.net/manual/en/errorfunc.configuration.php#ini.display-startup-errors http://php.net/manual/en/errorfunc.configuration.php#ini.display-startup-errors
- http://php.net/manual/en/errorfunc.configuration.php#ini.display-errors http://php.net/manual/en/errorfunc.configuration.php#ini.display-errors
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)