只是白屏甚至没有上传表单帮助我的代码没有显示错误。
继承我的代码 -
<?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);
?>
记住没有显示错误。 提前致谢。 如果我删除Imagecopyresampled下面的代码,我的意思是从标题到imagedestroy行 我只收到上传表格,但没有删除任何东西,我只得到页面左上角的一个小的破碎图像。
答案 0 :(得分:0)
您正在混合使用两种不能混合的方法:
您必须选择:
<img src="your_freshly_saved_image.jpg">
<img src="your_image_script.php?with_some_vars=perhaps">