无法在屏幕上输出缩略图我得到一个干净的白色屏幕,左上角有一个破碎的图像

时间:2014-05-01 15:31:48

标签: php mysql mysqli

只是白屏甚至没有上传表单帮助我的代码没有显示错误。

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); 

?> 

记住没有显示错误。 提前致谢。 如果我删除Imagecopyresampled下面的代码,我的意思是从标题到imagedestroy行 我只收到上传表格,但没有删除任何东西,我只得到页面左上角的一个小的破碎图像。

1 个答案:

答案 0 :(得分:0)

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

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

您必须选择:

  1. 您输出html。然后,您必须将图像另存为图像,并将其包含在图像标记中,如<img src="your_freshly_saved_image.jpg">
  2. 输出图像。然后你不能在这个脚本中输出任何其他内容,而另一个html / php页面中的图像源将是你的脚本:
    <img src="your_image_script.php?with_some_vars=perhaps">