可以';t输出配置文件页面的缩略图


can't output the thumbnail for profile page

如果我这样做,我就无法显示缩略图:

echo "<img width='300'height='300' src='images/".$row['image']."' alt='Profile Picture'>";

显示图片:

但当我这样做的时候,它对没有帮助

profile.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);
 
?> 

它给了我这些错误的帮助!

警告:imagecreatefromjpeg('images/IMAG0342.jpg'(:无法打开流:第60行C:''examplep''htdocs''newt.php中没有这样的文件或目录

警告:imagesx((要求参数1为resource,在第61行的C:''examplep''htdocs''newt.php中给出布尔值

警告:imagesy((要求参数1为resource,在第61行的C:''examplep''htdocs''newt.php中给出布尔值

警告:imagesy((要求参数1为resource,在第68行的C:''examplep''htdocs''newt.php中给出布尔值

警告:imagesx((要求参数1为resource,在第68行的C:''examplep''htdocs''newt.php中给出布尔值

警告:imagesx((要求参数1为resource,在第69行C:''examplep''htdocs''newt.php中给出布尔值

警告:imagecopyrasampled((要求参数2为资源,在第77行的C:''examplep''htdocs''newt.php中给定布尔值

此行错误:

$orig_image = imagecreatefromjpeg("'images/".$row['image']."'");

您在图像周围加上了单引号,因此php实际上是在查找目录'images和末尾带有引号的文件名。

应该是:

$orig_image = imagecreatefromjpeg("images/".$row['image']);

由于图像没有成功创建,因此之后所有需要该图像的行都会向您发出警告。