500 Internal Server Error PHP Script - Tried most answers

Paul Bentham

My script seems to be returning a 500 error whenever pictures are attached, however it is returning the files I wanted in my directory? I've tried phpinfo() and put a bespoke .user.ini in my directory and I'm still ending up with the error. I'm using Godaddy & Plesk if that helps?

<?php

set_time_limit(0);
ignore_user_abort(1);
ini_set('memory_limit','512M');

require('fpdf/fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Helvetica','B',10);
$pdf->Image('some-url',10,10,50,50,'gif');
$pdf->SetXY(70,28);
$pdf->Cell(0,0,"Title",0,0,'C');
$pdf->SetXY(70,40);
$pdf->Cell(0,0,"Job Completion Certificate",0,0,'C');
$pdf->SetY(60);
$pdf->Write(14,$Data);
$pdf->SetY(225);
if(! empty($_POST["signature"])){
$pdf->Image($_POST["signature"],null,null,0,0,'png');
};
$pdf->AddPage('P','A4');

$allowedExts = array("gif", "jpeg", "jpg", "JPG", "JPEG", "PNG","png");
$pictures = array("file1", "file2", "file3");
$counter = 10;

foreach ($pictures as $value)
{
if ( ! empty($_FILES[$value]["tmp_name"])
&&($_FILES[$value]["size"] < 4000000)
&& in_array(end(explode(".", $_FILES[$value]["name"])), $allowedExts))
{
  move_uploaded_file($_FILES[$value]["tmp_name"],$_FILES[$value]["name"]);
  $pdf->Image($_FILES[$value]["name"],25,$counter,80,80);
  //unlink($_FILES["file"]["name"]);
  $counter += 90;
}
else
  {
  echo $value." is either Invalid or Not Attached<br>";
  };    
};
$pdf->Output($_POST["Customer"]."_".$_POST["Location"].'.pdf', 'F');

print "Data Written"; 

?>  

If I comment out this section of the code:

foreach ($pictures as $value)
{
if ( ! empty($_FILES[$value]["tmp_name"])
&&($_FILES[$value]["size"] < 4000000)
&& in_array(end(explode(".", $_FILES[$value]["name"])), $allowedExts))
{
  move_uploaded_file($_FILES[$value]["tmp_name"],$_FILES[$value]["name"]);
  $pdf->Image($_FILES[$value]["name"],25,$counter,80,80);
  //unlink($_FILES["file"]["name"]);
  $counter += 90;
}
else
  {
  echo $value." is either Invalid or Not Attached<br>";
  };    
};

It works fine.

Edit:

After further inspection and changing my web.config file (see http://support.godaddy.com/help/article/3430/disabling-windows-custom-error-messaging?locale=en&ci=46061) I get this error:

PHP Strict Standards:  Only variables should be passed by reference in G:\PleskVhosts\mysite\httpdocs\action.php on line 48
Paul Bentham

I ended up having to change my code to the below:

...
foreach ($pictures as $value)
{
$temp = explode(".", $_FILES[$value]["name"]);
$extension = end($temp);    
if ( ! empty($_FILES[$value]["tmp_name"])
&&($_FILES[$value]["size"] < 4000000)
&& in_array($extension, $allowedExts))
{...

If anyone else struggles getting errors showing up on godaddy & plesk follow the link above and put the web.config file in your root folder and the folder that your page is in. Once you can see where the problem is it's a whole lot easier to solve!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Internal server error 500 when calling php script

Unexplained PHP error (Internal Server Error 500)

PHP code giving 500 internal server error

POST 500 Internal Server Error -- PHP

Internal Server Error 500 on .PHP pages only

500 internal server error php, how to solve?

Slim PHP 500 Internal Server Error

Internal Server Error (500)

cURL - prompt script works while same request with curl-php doesn't (Internal server error 500)

WSGI Script Cannot Be Loaded as Python Module -- 500 Internal Server Error

PHP SQL Server : 500 Internal server error with specific query

php MySQL insert into error, 500 internal server error

removing php extension in htaccess returns an internal server error (500)

Why "500 internal server error" with index.php permission 666?

Codeigniter 500 internal server error due to index.php

Heroku php slim app - 500 internal server error

Getting on 500 Internal Server Error On PHP saving Canvas as Image

500 Internal Server Error in PHP 8.1 Array with wordpress

Php file sometimes causing 500 Internal Server Error

update-php class causing 500 internal server error

IIS Giving a 500 Internal Server Error When Serving a PHP file

PHPMyAdmin 500 Internal Server Error in Apache due to PHP Version

NetworkError: 500 Internal Server Error - php web service

phpMyadmin Internal Server Error 500

500 internal server error on laravel?

Retrofit: 500 internal server error

500 Internal Server Error Heroku

500 Internal Server Error Hosting

500 - Internal server error with no details