dongpanshi2839 2015-07-15 23:46
浏览 32
已采纳

PHP表单功能正在运行但返回空白页面

I'm working on a function to upload images to my website fileserver and at the same time would create a thumb preview and create an entry to my mysql database. So long the function to upload_image() is working, it uploads the image and creates a thumb perfectly.

The issue is, that when I click the submit button to upload the image selected, the PHP function do its job but will return a BLANK PAGE. Yes, I know, "another blank page of death question, go find all the other 53 posts related to this question and find a solution" right? Well, it's not that simple.

I have tried every single method in those questions and another bunch that I've found over this forsaken place called internet and nothing works for me, I always get the same Blank Page of death with no warning or error.

What have I tried would you ask? The following would just represent a relevant set of solutions that I recall:

  1. Configuring PHP.INI's options for error: DONE. Even creating the log file for every single detailed error.
  2. Overriding PHP.INI's options from the php file function with the settings: DONE. Also I have used a script from some answers that override error log protocol.
  3. Place an exit('wtf') function from start to bottom to see if its an Syntax error or an error on a certain line: DONE. Every single line will print WTF on the god forsaken Blank Page.

Well, there are other solutions I have tried, be my guest and offer some answers and I would tell you if I have already tried it.

Lets get to it then. My HTML code that calls the php file is:

<form action="assets/php/image_uploader.php" method="post" enctype="multipart/form-data">                        
    <input type="file" name="myfile" id="fileToUpload">
    </br>
    </br>
    <input type="text" name="title" value="Titulo" size="64">
    <br>
    <br>
    <input type="submit" value="Upload Image" name="submit">
</form>

And my image_uploader.php code is:

<?php
function upload_image()
{
$root = realpath($_SERVER["DOCUMENT_ROOT"]);

$name =  "image_" . date('Y-m-d-H-i-s') . "_" . uniqid() . ".jpg";
$type= $_FILES["myfile"]["type"];
$size= $_FILES["myfile"]["size"];
$temp= $_FILES["myfile"]["tmp_name"];
$error= $_FILES["myfile"]["error"];

if ($error > 0)
{
    die("Error uploading file! code $error.");
}
else
{
    if($type=="image/png" || $size > 2000000)//condition for the file
    {
        die("Format  not allowed or file size too big!");
    }   
    else
    {
        if(move_uploaded_file($temp, $root . "/images/fulls/" . $name))
        {
            list($ancho, $alto) = getimagesize($root . "/images/fulls/" .$name);
            $nuevo_alto = 212;
            $nuevo_ancho = 212;
            $dx = 0;
            $dy = 0;
            $sx = 0;
            $sy = 0;
            if($ancho == $alto)
            {           
            }
            else
            {
                if($ancho > $alto)
                {
                    $nuevo_ancho = $ancho * (212/$alto);
                }
                else
                {
                    $sy = $alto/2 - $nuevo_alto/2;
                    $alto = $ancho;
                }
            }
            $thumb = imagecreatetruecolor($nuevo_ancho, $nuevo_alto);
            $origen = imagecreatefromjpeg($root . "/images/fulls/" .$name);
            imagecopyresampled($thumb, $origen, $dx, $dy, $sx, $sy, $nuevo_ancho, $nuevo_alto, $ancho, $alto);
            imagejpeg($thumb, $root . "/images/thumbs/" .$name);
            imagedestroy($thumb);
            echo "The file ". basename( $_FILES["myfile"]["name"]). " has been uploaded.";
        }
    }
}
}
if(isset($_POST['submit']))
{
   upload_image();
} 
?>
  • 写回答

2条回答 默认 最新

  • douxi0098 2015-07-16 03:02
    关注

    Placed the code into the HTML file which was renamed later to have the extension .php and called the function in the form section as:

    <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post" enctype="multipart/form-data">
    <input type="file" name="myfile" id="fileToUpload">
    </br>
    </br>
    <input type="text" name="title" value="Titulo" size="64">
    <br>
    <br>
    <input type="submit" value="Upload Image" name="submit">
    </form>
    

    And now it works as if it was magic, I do not know if htmlspecialchar() function has anything to do with it, but now the code works with no errors. Therefore I would post this as an answer but reminding you to not consider this as a solution to the BLANK PAGE death screen.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀