The server (maddogdomains) throws error 503, when the phpspreasheet plugin loads an Excel of 22MB and more than 40,000 records, see line 10 ($reader->load($inputFileName)) of the following code:
$data = array(
'upload_data' => $this->upload->data()
);
$inputFileType = 'Xls';
$inputFileName =$data['upload_data']['full_path'];
$cache = new FilesystemCache();
\PhpOffice\PhpSpreadsheet\Settings::setCache($cache);
$reader = IOFactory::createReader($inputFileType);
$spreadsheet = $reader->load($inputFileName);
I have increased memory_limit and all the resources in the php.ini and the 503 error persists. How do I solve this error?
It's a question of time spent by PHPSpreadsheet to read the file.
Try to put set_time_limit(0); at top of your script
Related
I was successfully able to get an image(which is stored as a BLOB file) from an API endpoint in guzzle, but I am having issues displaying this BLOB file as an image
I have tried several PHP functions for manipulating and converting a BLOB file to an image but all has been abortive.
after sending the request to my guzzle trait, I decided to var_dump the result to be sure that it was successful
$userid = $_COOKIE['id'];
$url = 'users/image/'.$userid;
$requestResult = $this->sendGetWithHeader('users/image/'.$userid);
$result = $requestResult->getBody()->read(1024);
//$res = file_get_contents($result);
// fopen($result, 0);
var_dump($result);
echo "<hr>";
var_dump($requestResult);
// $code = $requestResult->getStatusCode();
// var_dump($code);
My expected result is an image file but the actual is still the raw BLOB file gotten from my Guzzle request
string(1024) "����JFIF��� ��V�"��6 ���UG_ks1��r�[�% ��JMd�CL,��8�Q�B�yoA��g�p�-�a�f� D �)8#�.)ɠ� �yea#4��ԃ(��t��Ew��մPV'J��R��u������Ju��U ��ԥ��zѩaė��ya$�2�C�Sa�R$�4� ���� 2t��$��L�D���R�$�ґ-&RVdm��IDq)Jc�"'9�;/ �sb{��Z�r�̮��Q_MR=5�Gt���ddA�6�Fa�L���JGi�kh�d�FA�%(�$� �����.�� H�)��-BL������h|#���WW)r�"V[V2˚:��j��˩�>��-$��I�Y�#%dRL(K�(�-�m�I�t��R�JV#�I&JR��0����O2��d�-e#5�2}�2�D'��,Bע��{��!�k�Uw�2ʶ�]cAD�WPw���$��!�Ғu�X!��(�D%I0i�����Lye XI9) �[Nc����#!�miY,Rkiq(���$����mƬ��y��a����崔͒�t7"����͌ΊJgk Q��Ah�Iq$���ʍA�FmJ���7��AJ�a/�rB�"02A����#�d��J%D� �P�yH���m\ż>�i$��I�(�3jm�542k,��t#��#��#D�F�TJDP" �Z(��7�IZ���h9)$��$�Ԣ�Y� m�D�I�4�����Da�%DX�o ���fhh�.�c��aQhcΉ�٠��)��"
Save your blob response to a file as follows
$stream = \GuzzleHttp\Psr7\Utils::streamFor($requestResult->getBody());
file_put_contents('path/to/file.extension',$stream->getContents())
See Convert blog image to file
Look at this example - https://github.com/andriichuk/php-curl-cookbook#download-file
Use 'sink' option to save file from request:
use GuzzleHttp\Client;
use GuzzleHttp\RequestOptions;
$imageFilePath = __DIR__ . '/resource/image.jpeg';
$imageFileResource = fopen($imageFilePath, 'w+');
$httpClient = new Client();
$response = $httpClient->get(
'https://httpbin.org/image/jpeg',
[
RequestOptions::SINK => $imageFileResource,
]
);
if ($response->getStatusCode() === 200) {
echo 'The image has been successfully downloaded: ' . $imageFilePath;
}
I'm using Laravel Excel 2.1.0 in a local project to write a row into an excel file.
This is my code:
$filePath = storage_path('myfile.xls');
$rows = \Excel::load($filePath, function($reader) {
$sheet = $reader->sheet(0);
$sheet->appendRow(
array(
'Hello'
)
);
});
Everything works and a new line was appended to my file.
Sometimes can happens the excel file is opened while user try to append a new line. In this case Laravel, rightly, show me this error:
fopen(mypath\myfile.xls): failed to open stream: Resource temporarily unavailable
How can I handle this error in order to skip the function and go on with my code without append the row?
I solved in this way:
$filePath = storage_path('myfile.xls');
$fp = #fopen($filePath, "r+");
if($fp) {
$rows = \Excel::load($filePath, function($reader) {
$sheet = $reader->sheet(0);
$sheet->appendRow(
array(
'Hello'
)
);
});
}
Have a problem while trying to queue mail that have attachment.
I can send an email without any problems without queue. Attachment is correct and can be opened. Problem appear when I try to queue that email. Excel generated by maatwebsite/excel lib
Error:
InvalidPayloadException in Queue.php line 89:
5
I found that this part of code throws this error:
...\vendor\laravel\framework\src\Illuminate\Queue\Queue.php
protected function createPayload($job, $data = '', $queue = null)
{
$payload = json_encode($this->createPayloadArray($job, $data, $queue));
if (JSON_ERROR_NONE !== json_last_error()) {
throw new InvalidPayloadException;
}
return $payload;
}
My code looks like:
excel = Excel::create('Report', function($excel) {
$excel->sheet('Sheetname', function($sheet) {
$sheet->fromArray([['aaa']]);
});
})->string('xlsx');
Mail::to('mail#mail.com')
->queue(new Report($excel));
I've tried to utf8_encode($excel) but then I cannot open mail attachment and I think that any operation on generated excel will corrupt file...
This problem also appear when I try to attach excel file from disk.
Any help?
my project ran well in localhost using xampp but in remote server I've got an error when Im trying to upload or update an image,..
warning:
Message: move_uploaded_file(images/1458100947_2.jpg):
failed to open stream: Permission denied
here is the code were the errors located.
$imagename = $this->person->view($this->input->post('id'))->image;
if(file_exists("images/$imagename")) unlink("images/".$imagename);
$fileName = time(). '_' .$_FILES["image"]["name"];
move_uploaded_file($_FILES["image"]["tmp_name"],$output_dir.$fileName); //this line
$targetPath = 'images/' . $fileName;
$config_resize['image_library'] = 'gd2';
$config_resize['create_thumb'] = FALSE;
$config_resize['maintain_ratio'] = TRUE;
// $config_resize['master_dim'] = 'height';
$config_resize['quality'] = "80%";
$config_resize['source_image'] = $targetPath;
$config_resize['height'] = 600;
$config_resize['width'] = 1024;
// $config_resize['thumb_marker'] = '';
$config_resize['new_image'] = 'images/' . $fileName;
$this->image_lib->initialize($config_resize);
$this->image_lib->resize();
$uploaded = TRUE;
I am trying to google on how to set the permission to 777 in codeigniter but no luck.. here is my project link http://mysports.orgfree.com. use this admin account.
username: mak password: mak
to login and click the edit button then upload some image.. the error will show after that.. thank you...
Hello you can give 2 way permission
1) directly give folder permission using this way
chmod("folder name with path", 755);
2)directly give file permission using this way and use this code after move_uploaded_file function
chmod("file name with path", 644);
I was able to fix my permission issue by using SmartFTP to upload the files, because it provides an easy way to set the permission. This resolved my question and my code works now.
When i run my aaplication in external server i get eror ,
Message: Login::include_once(application/third_party/mpdf/mpdf.php) [function.Login-include-once]: failed to open stream: No such file or directory.
The same application was running perfect in local server. Can anyone please suggest what could be wrong with it. My controller function ,
function pdfapp() //for test run individually
{
$this->load->model('Registration_model');
$appno='4/SCSELB/2013/KL01';
$data['table'] = $this->Registration_model->getall_app($appno);
$data['own_land'] = $this->Registration_model->get_ownland($appno);
$data['loan_data'] = $this->Registration_model->getloan_data($appno);
$apppdf='4_SCSELB_2013_KL01';
$data['apppdf']=$apppdf;
$pdfFilePath = FCPATH."reports/application/$apppdf.pdf";
if (file_exists($pdfFilePath) == FALSE)
{
ini_set('memory_limit','32M');
$html = $this->load->view('pdf_report2', $data, true);
include_once APPPATH.'third_party/mpdf/mpdf.php';
$mpdf=new mPDF('c');
$mpdf->SetFooter(' copyright# KSDC'.'|{PAGENO}|'.'Applied on '.date('d-M-Y H.i.s'));
$mpdf->WriteHTML($html);
$mpdf->Output($pdfFilePath, 'F');
}
$this->load->view('pdf_report2',$data);
}
The error you're getting is of a file not existing, Did you you debug this line ?
APPPATH.'third_party/mpdf/mpdf.php'; ?
what path do you get if you var_dump it?