This question already has an answer here:
Authenticity of uploaded pdf files
(1 answer)
Closed 9 years ago.
i am trying to check the pdf before upload.
I want to check the pdf is malicious or not.
for example: i save a php file as pdf and upload it. but server shows an error that it is not a valid pdf.
so how can i check the pdf is real or not in php?
Please see the Fileinfo extension for php: http://www.php.net/fileinfo also example of usage here: http://www.php.net/manual/en/function.finfo-open.php
L.E: Please note, FileInfo is the only way you should check your file types. Do not use their extensions to check against the file type, this is a huge mistake.
Also, if Fileinfo is not available for some reason and you cannot install it and you have shell access, you can just : $info = exec('file -ib ' . escapeshellarg($filePath)); print_r($info);
Related
This question already has answers here:
How to update a website without making it go down?
(3 answers)
Closed 3 years ago.
when I update a php file via ftp (filezilla), pages using that file stop to work until transfer is complete. The server is linux with nginx/php-fpm, but I had the same problem with apache. The only "solution" I found is to edit directly the php file on a server remote shell, and update the content. But this is a very uncomfortable solution.
Is there anybody with a better solution?
Thanks
It is normal if you are doing upload via FTP. the Best solution is using Continues Deployment services with zero downtime approach.
Continuous deployment without downtime
But if you talk about one file. You can just check php file if it exists or correct uploaded file else you can use old copy of this file.
Somesthing like this :
$file = 'uploaded.php';
$oldFile = 'uploaded_old.php';
if (file_exists($file)) {
require_once($file);
} else {
require_once($oldFile);
}
This question already exists:
PHP's white screen of death [duplicate]
Closed 7 years ago.
I am trying to make use of RESTful service using php. I am able to get the JSON format output wen i run the php file through terminal. But if I try running it using apache webserver i am getting a blank web page. please help me.
<?php
$client=curl_init("http://wwwdev.ebi.ac.uk/pdbe/api/emdb/entry/map/EMD-1200");
curl_setopt($client,CURLOPT_RETURNTRANSFER,1);
//get response from resource
$response=curl_exec($client);
echo $response;
//decode
// $res=array(json_decode($response));
// echo $res;
?>
This is my code.
Run
phpinfo();
and make sure you have curl enabled!
If not then uncomment this line from php.ini.
;extension=php_curl.dll
Then restart your server.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Creating an image without storing it as a local file
i need create a image with gd and upload it to anoter server with curl in php .
so i met a problem : a gd image resource can't use as a file stream resource with curl.
is there some way of make a gd image resource into a file stream resource ?
--update--
the local disk is not writeable .
You won't be able to use it is as a resource, but this should work to capture a JPEG of the image into a local variable.
ob_start();
imagejpeg($image);
$jpeg_image = ob_get_clean();
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Forcing to download a file using PHP
PHP - send file to user
Is it possible to serve a file from another server , and change the name.
I have all files uploaded in another server but names are changed.I want to hit this server and fetch file from it but want to change it s name.
I wrote a simple curl script , but this adds extra traffic to my php server as well so i will be billed twice for each file and more over it will use php memory as well(if file size increases site may crash)
$init = curl_init();
curl_setopt_array($init, $opArray);
$myFile = curl_exec($init);
$info = curl_getinfo($init);
curl_close($init);
headers ....
echo File
All i am interested is in headers part but for this i need to get file into php server can this be avoided ?
You can use the following headers:
Content-Type: xxx/xxx
Content-Disposition: attachment; filename=theFilenameYouWant.xxx
If you want to avoid heavy memory consumption and if you are using Apache as web server, you can take a look at the mod_xsendfile:
http://codeutopia.net/blog/2009/03/06/sending-files-better-apache-mod_xsendfile-and-php/
This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Read pdf files with php
Hi,
I have a bulk of pdf documents. I want to read that using php script. I searched a lot, but everyone is about creating pdf files. Here I dont want to create pdf file but I want to read it. Is there any way to read it php?
-Arun
To just get the text from a PDF file, try these:
- http://davidwalsh.name/read-pdf-doc-file-php
- http://www.webcheatsheet.com/php/reading_clean_text_from_pdf.php (more in-depth)
For a more heavyweight solutions, have a look at:
- http://www.setasign.de/products/pdf-php-solutions/fpdi/
You can easily read the contents of a PDF file using a command-line utility like Pdftotext which you can call through exec.
This is an example of what i mean, actually using system
system("pdftotext your.pdf /tmp/txtfile.txt");
$text = file_get_contents("/tmp/txtfile.txt");
EDIT
didn't know about the dash syntax - this is even better:
$content = shell_exec('pdftotext your.pdf -');
This does require pdftotext to be installed on your server though. On a CentOS server this would be:
yum install xpdf