Get File Headers - php

I want to get file headers for compare i.e
if (file_header == image)
{
//do something
}
but I can't figure out how to do it...
I was looking mime-content-type, but it is not working for me... then finfo-file doenot work because I have only php 5.2 version... So can anyone help me with my problem?
UPD1 also I can't use fileinfo()

So I solved my problem with deleting one extra check and all is working now!

Related

Have anybody an useful implementation of rowClone, blockClone from phpWord (https://github.com/PHPOffice/PHPWord)?

Currently I'm having problems with rowClone and blockClone specially. In the documentation they says that if we use rowClone over a table with merged cells, the function (rowClone) will clone the adjacents rows, so I said, ok well, it looks pretty nice. So I made a table as you can see in the image 1, but when I execute the script, the function rowClone doesn't work as I was expecting.
Then reading the documentation deeper, I realized that there is another function called blockClone, but when I tried to use it, surprise, it doesn't work neither.
Finally I started looking for solutions on the Internet, but nothing they proposes help me, so please if you have any advice, hack, anything, please comment. Thanks in advance.
Image 1: template (.docx)
Image 2: result after processing the template
I found the bug in the source code. There is a space in a regular expression that made function preg_match does not match anything. Following I show you how to fix it:
This is the original code:
if (!preg_match('#<w:vMerge/>#', $tmpXmlRow) &&
!preg_match('#<w:vMerge w:val="continue" />#', $tmpXmlRow)) {
break;
}
And this te code fixed.
if (!preg_match('#<w:vMerge/>#', $tmpXmlRow) &&
!preg_match('#<w:vMerge w:val="continue"/>#', $tmpXmlRow)) {
break;
}
The above if is between 298 and 302 in the source code (https://github.com/PHPOffice/PHPWord/blob/develop/src/PhpWord/TemplateProcessor.php)
I have hope it could help you!

PHP getting remote url image file size doesn't wait for content-length header to be set

I know this question has been asked millions of times, but please actually take the time to understand my problem before marking as duplicate or closing.
So I am using the following code. For some reason it gets all of the correct header information the first time I run the code EXCEPT for content-length. The second time I run the code it actually gets it correctly. I am retrieving the images from Facebook API if that changes anything.
function remote_filesize($url) {
$data = get_headers($url, 1);
if(isset($data['Content-Length'])) {
return (int) $data['Content-Length'];
}
else {
return -1;
}
}
Edit
Gotta love when you get downvoted with no explanation. Personally I think it should be required to provide a reason.
Anyway, this is still an issue, but in case anyone googling this needs a solution for getting the remote filesize, I would suggest using this awesome snippet from the PHP docs http://php.net/manual/en/function.filesize.php#114952
Sounds like a server caching issue.
So you may have to issue a full GET request instead of just a HEAD request.
Also, maybe check different casing -- 'content-length:' -- lowercase.

Php extracting a zip, strange behaviour

so i'm currently facing a strange behaviour in php, it might be something fairly easy to solve but I have been searching and looking my code for an 1h or 2, and i'm still stuck a the same place. Thanks for your help in advance.
So here is my problem
So I have this function
function extractZip($pathToZip, $pathToExtract){
$zip = new ZipArchive();
if ($zip->open($pathToZip) === true){
$zip->extractTo($pathToExtract);
$zip->close();
}
unlink($pathToZip);
}
And I use it with a zip built like this
/folder1/folder2/folder3/files
The problem is when I extract it as so
extractZip("path/to/zip.zip", "path/to/extract");
the structure becomes weird
/folder1/folder2/folder3/files -> this is fine
/folder2/folder3 -> this is weird because it recreates all the folders
and they are empty, but I don't want those useless folder!
Thank you and if something is not clear just ask questions
Upgrading php to the newest version corrected the problem, (php 5.6)

Not found yui-moodlesimple-min.css

I have a little problem, I want to do accesible my webpage(with Moodle), I used http://jigsaw.w3.org/css-validator/ and I have a lot of errors, the uri is on: theme/yui_combo.php?rollup/3.17.2/yui-moodlesimple-min.css but I don't found it.
I look it the file(yui_combo.php) but I dont found anything, can anyone help me? thanks
Ok this file is generated automatically from files:
--versionyui--/widget-base/assets/skins/sam/widget-base.css
--versionyui--/widget-stack/assets/skins/sam/widget-stack.css
--versionyui--/overlay/assets/skins/sam/overlay.css
--versionyui--/widget-modality/assets/skins/sam/widget-modality.css
--versionyui--/panel/assets/skins/sam/panel.css
At least in my case

Why Do Single Line PHP Comments Break Page?

I apologize if this has been answered, but I haven't been able to find anything about it. I've been having trouble with a certain block of PHP code on my server and have finally realized that it doesn't like single line comments. With this code, the method get_all_articles is never called.
<?php
$article_class = new Articles();
// Fetch all articles
$articles = $article_class->get_all_articles();
?>
However, removing the comment or converting it to a block comment allows the page to render perfectly. I realize that I've already figured out what's causing the problem, but what I'm looking for is why or how I might be able to fix it. Any help would be greatly appreciated. Thanks!
Maybe the formatting is getting lost on upload to where line breaks are being deleted? Try downloading the PHP file after you've uploaded it and see if the line breaks are still intact.
This can be frustrating... One time I had an if statement that would ALWAYS execute, no matter what the values were...
Started out as this, where $x was equal to 5 (I verified this with debugging)
if($x > 10);
{
....
}
Eventually, I had it down to this:
if(false);
{
echo("This should never happen");
echo("but it does!!!!!!!");
}
After much loss of hair, I realized that I had a semi-colon at the end of the if() line, therefore translating into:
if(false)
/*do nothing*/;
{
//Nice block that always executes
}
The moral of this story is that while the problem you percieve is actually giving you a problem, it is not a PHP problem. Try to find out the root cause by first verifying that the actual code that is executing is EXACTLY what you typed. Re-download the file, publish with different protocol, publish as binary, check sha1sum() on files to make sure the same... Look and look and you will find it.
Let us know.

Categories