问题
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
回答1:
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!
来源:https://stackoverflow.com/questions/21222079/500-internal-server-error-php-script-tried-most-answers