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:
- Configuring PHP.INI's options for error: DONE. Even creating the log file for every single detailed error.
- 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.
- 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();
}
?>