无法在屏幕上输出缩略图,我得到了干净的白色屏幕,左上方有一点破损的图像 [英] cant output the thumbnail on the screen i get a clean white screen with a little broken image on the top left

查看:66
本文介绍了无法在屏幕上输出缩略图,我得到了干净的白色屏幕,左上方有一点破损的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

纯白屏幕甚至无法获取上传表单帮助,这里我的代码没有显示错误.

just white screen not even getting the upload form help heres my code no errors are displayed.

这是我的代码-

<?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行 我只得到上载表格,但没有删除任何内容,除了页面左上方的一小点破损图像之外,什么也没得到.

remember no errors are displayed. thanks in advance. if i delete the code below the Imagecopyresampled i mean from header to imagedestroy line i get the upload form only but without deleting anything i get nothing but a small broken image on top left of the page.

推荐答案

您正在混合两种无法混合使用的不同方法:

You are mixing two different approaches that you cannot mix:

  • 在代码中间输出html
  • 在代码末尾输出图像

您必须选择:

  1. 您输出html.然后,您必须将图像另存为图像,并将其包含在图像标签中,例如
    <img src="your_freshly_saved_image.jpg">
  2. 您输出图像.然后,您将无法在此脚本中输出其他任何内容,而另一个html/php页面中的图像源将是您的脚本:
    <img src="your_image_script.php?with_some_vars=perhaps">
  1. You output html. Then you have to save the image as an image and include it in an image tag like
    <img src="your_freshly_saved_image.jpg">
  2. You output an image. Then you cannot output anything else in this script and the source of an image in another html / php page would be your script:
    <img src="your_image_script.php?with_some_vars=perhaps">

这篇关于无法在屏幕上输出缩略图,我得到了干净的白色屏幕,左上方有一点破损的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆