500内部服务器错误的PHP脚本-尝试了大多数答案[英] 500 Internal Server Error PHP Script - Tried most answers

本文是小编为大家收集整理的关于500内部服务器错误的PHP脚本-尝试了大多数答案的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

每当附加图片时,我的脚本似乎都会返回500错误,但是它正在返回我想要的文件吗?我已经尝试了phpinfo(),并在我的目录中放了一个定制的.user.ini,但我仍然遇到错误.如果有帮助,我正在使用Godaddy&Plesk?

<?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"; 

?>  

如果我评论了代码的这一部分:

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>";
  };    
};

它可以正常工作.

编辑:

进一步检查并更改我的web.config文件(请参阅 http://support.godaddy.com/help/article/3430/disabling-windows-custom-eror-ror-messaging?locale = en&ci = 46061 )/p>

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

推荐答案

我最终必须将代码更改为以下:

...
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))
{...

如果其他人努力在GoDaddy&Plesk上出现错误,请按照上面的链接并将web.config文件放入您的页面文件夹和页面所在的文件夹中.一旦您可以看到问题在哪里,就是整个问题更容易解决!

本文地址:https://www.itbaoku.cn/post/2090945.html

问题描述

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

推荐答案

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!