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 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 Macbookpro 连接热点正常上网,连接不了Wi-Fi。
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程