只是白色屏幕,甚至没有得到上传表单的帮助,所以我的代码没有显示错误。
newt.php
这是我的代码-
<?php
require_once('includes/config.inc.php');
require_once('includes/functions.inc.php');
include("includes/html_codes.php");
session_start();
$username = $_SESSION["username"];
if ($_SESSION['logged_in'] == false) {
// If user is already logged in, redirect to main page
redirect('lo.php');}
?>
<?php
if(isset($_POST['submit'])){
$temporary_name=$_FILES['file']['tmp_name'];
move_uploaded_file($_FILES['file']['tmp_name'],"images/".$_FILES['file']['name']);
$mysqli = new mysqli(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
$q = mysqli_query($mysqli,"UPDATE users SET image = '".$_FILES['file']['name']."'WHERE username = '".$_SESSION['username']."'");
}
?>
<!DOCTYPE html>
<html>
<head>
<head>
<title>Profile</title>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="css/main.css"/>
<link rel="stylesheet" href="css/form.css"/>
<link rel="stylesheet" href="css/register.css"/>
<body>
<header>
<?php topBarl(); ?>
</header>
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="file">
<input type="submit" name="submit">
</form>
<?php
$mysqli = new mysqli(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
$q = mysqli_query($mysqli,"SELECT * FROM users WHERE username = '$username'");
$row = mysqli_fetch_assoc($q);
$width= 275;
$height= 275;
$orig_image = imagecreatefromjpeg("images/".$row['image']);
if (imagesx($orig_image) > imagesy($orig_image)) {
$y = 0;
$x = (imagesx($orig_image) - imagesy($orig_image)) / 2;
$smallestSide = imagesy($orig_image);
}
else {
$x = 0;
$y = (imagesy($orig_image) - imagesx($orig_image)) / 2;
$smallestSide = imagesx($orig_image);
}
$image_p = imagecreatetruecolor($width, $height);
Imagecopyresampled($image_p,$orig_image,0,0,$x,$y,$width,$height,$smallestSide,$smallestSide);
header( 'Content-Type: image/jpeg' );
imageJPEG($image_p, NULL, 100);
imagedestroy($image_p);
imageDestroy($orig_image);
?>
请记住,没有显示任何错误。提前谢谢。如果我删除Imagecopyreseampled下面的代码,我的意思是从标题到imagedestroy行我只收到了上传表单,但没有删除任何内容。我只收到页面左上角的一张小图片。
您正在混合两种无法混合的不同方法:
- 在代码中间输出html
- 在代码末尾输出图像
您必须选择:
- 您可以输出html。然后,您必须将图像保存为图像,并将其包含在图像标签中,如
<img src="your_freshly_saved_image.jpg">
- 输出图像。然后,您无法在该脚本中输出任何其他内容,而另一个html.php页面中的图像源将是您的脚本:
<img src="your_image_script.php?with_some_vars=perhaps">