嘿伙计们,我有一个可以上传 .csv 文件的功能。现在发生的事情是,公司会来上传一个包含数千名员工的 csv 文件。现在我有一个问题。我不断得到:
PCI 内部错误、最大执行时间和上传的文件。
我把这个带到我们的提供商 Winhost 那里,他们把它提高到 600 秒 - 10 分钟。现在埃文在这样做之后我仍然遇到麻烦。相同的超时消息和所有内容。所以我不知道它是否没有被踢出去或者发生了什么,但我真的需要一些帮助。
代码:
session_start();
if(!isset($_SESSION['myusername'])){
header("location:/PCG/mainlogin.php");
}
require_once "Mail.php";
$hostname="";
$username="";
$password="";
$database="";
if (!empty($_POST['name'])){
$member = $_POST['name'];
$memval = 1;
}
function returnBack(){
header("Location:PCG/csvuploaderform.php?seterror=1");
exit;
}
function returnBackfile(){
header("Location:PCG/csvuploaderform.php?seterror=2");
exit;
}
if (isset($_POST['submit'])){
/*******************************CHECK TO MAKE SURE FORM IS PROPERLY FILLED AND GET NAME OF COLUMNS IN CSV FILE *********************************************************/
if (!empty($_FILES['file']['error'] ) )
{
echo "file";
$seterror =1;
returnBack();
}
if (empty($_POST['firstname'])){
$seterror =1;
returnBack();
}
if (empty($_POST['lastname'])){
$seterrro =1;
returnBack();
}
if (empty($_POST['email'])){
$seterror =1;
returnBack();
}
if (empty($_POST['phone'])){
$seterror =1;
returnBack();
}
if ($seterror != 1){
$file = $_FILES['file']['tmp_name'];
$handle = fopen($file , "r");
$fileop = fgetcsv($handle,1000,",");
$fileop=array_map("strtoupper",array_map("trim",$fileop));
$firstname_index = array_search(strtoupper($_POST["firstname"]),$fileop);
if ($firstname_index===false){
returnBack();
}
$lastname_index = array_search(strtoupper($_POST['lastname']),$fileop);
if ($lastname_index===false){
returnBack();
}
$email_index = array_search(strtoupper($_POST['email']),$fileop);
if ($email_index===false){
returnBack();
}
$phone_index = array_search(strtoupper($_POST['phone']),$fileop);
if ($phone_index===false){
returnBack();
}
$date = date("Y-m-d");
/***********************ASSIGN COLUMN VALUES TO ACCORDING VARIABLES AND INSERT THEM INTO CSV TABLE IN DB *************************************/
try {
# MySQL with PDO_MYSQL
$DBH = new PDO("mysql:host=$hostname;dbname=$database", $username, $password);
$DBH->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
}
catch(PDOException $e) {
echo "I'm sorry, I'm afraid I can't do that.";
file_put_contents('PDOErrors.txt', $e->getMessage(), FILE_APPEND);
}
/*$fileop = fgetcsv($handle,1000,",")*/
if ($memval != 1){
$memberview = $_SESSION['myusername'];
}
else{
$sql ="SELECT username FROM members WHERE companyname =:companyname";
$sth=$DBH->prepare($sql);
$sth->execute(array(':companyname' => $member));
while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
$check = $row;
$memberview = $check['username'];
}
}
$j = 0;
while (($fileop=fgetcsv($handle)) !== false)
{
$fileop=array_map("trim",$fileop);
$firstname[$j] = $fileop[$firstname_index];
if (empty($firstname[$j])){
returnBackfile();
}
$lastname[$j] = $fileop[$lastname_index];
if (empty($lastname[$j])){
returnBackfile();
}
$email[$j] = $fileop[$email_index];
if (empty($email[$j])){
returnBackfile();
}
$phone[$j] = $fileop[$phone_index];
if (empty($phone[$j])){
returnBackfile();
}
$csvusername[$j] = $firstname[$j] . $lastname[$j];
$csvpasswordname[$j] = $lastname[$j] . $firstname[$j];
$status = "Open";
$sql ="SELECT username FROM csvdata WHERE username =:csvusername";
$sth=$DBH->prepare($sql);
$sth->execute(array(':csvusername' => $csvusername[$j]));
while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
$csvusername[$j] = $firstname[$j] . $lastname[$j] . rand(1,20);
}
$sql ="SELECT password FROM csvdata WHERE password =:csvpasswordname";
$sth=$DBH->prepare($sql);
$sth->execute(array(':csvpasswordname' => $csvpasswordname[$j]));
while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
$csvpasswordname[$j] = $lastname[$j] . $firstname[$j] . rand(1,20);
}
$j++;
}
for($i =0; $i<$j; $i++){
$sth = $DBH->prepare("INSERT INTO csvdata (firstname, lastname, email, phone, username, password, status, memberview, statuschangedate) VALUES (?,?,?,?,?,?,?,?,?)");
$sth->execute(array($firstname[$i], $lastname[$i], $email[$i], $phone[$i], $csvusername[$i], $csvpasswordname[$i], $status, $memberview, $date));
$from = "email.com";
$to = $email[$i];
$subject = "";
$body = "message.....";
$host = "";
$username = "";
$password = "";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));
//$mail = $smtp->send($to, $headers, $body);
}
$email = "";
$from = "";
$to = $email;
$subject = "";
$body = ",
";
$host = "";
$username = "";
$password = "";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));
//$mail = $smtp->send($to, $headers, $body);
header("Location:PCG/memberinterface.php?getmsg=11");
exit;
}
}
$DBH = null;
因此,如果您有任何发现错误的地方,请告诉我!出了点问题,我需要弄清楚!
大卫,
谢谢!
更新:
好的,伙计们在查看并停止发送电子邮件功能后,我注意到它的运行速度非常快。那么如何加快这封电子邮件的发送速度或防止它让页面运行这么长时间呢?