Activate pdf library in php - Windows (32 bit) - php

I have an Apache server running PHP-5.3.0 for Windows. For the creation of pdf files, I need to activate the pre-bundled pdf library (referred here) in my php by editing the configuration file. How can I do this?
Or is there any other way to enable pdf creation?

Go to PHP's root directory > php.ini. Ctrl+F 'extension=php_pdflib.dll' and remove the semicolon (;) at the start of the line. Then restart Apache. If the semicolon isn't there, then it should already be activated. If there isn't any results from the Ctrl+F, it likely means you don't have it installed. You could try adding 'extension=php_pdflib.dll' (anywhere will do).

You can use a small file to test whether the library is loaded, just write in it:
<?php phpinfo();
Watch for php.ini in the output of this script, and add the following line to the file (you may need additional privileges to do that, right click your editor -> Run as Administrator):
extension=php_pdflib.dll
Restart apache, and check that pdf has been installed by checking the aforementioned phpinfo file.
Unless you're doing really advanced PDF stuff (and you need the non-free version of php-pdf for that), I can really recommend Prince XML. It converts XML and HTML into PDF and adds additional CSS properties, like page dimensions and numbers, PDF bookmarks and the like. Their documentation is better in demonstrating that than any of their marketing pages.

I solved it using TCPDF.. Its easy to handle. No need to edit php.ini.

Related

.php files doesn't work in Visual Studio Code

I think I broke mi VS Code trying to join php and html syntax when I have a php file with html and php code.
The problem is that VS Code doesn't recognize .php files. The Select Language Mode shows as a 'Plain Text' and when I try to configure file association for '.php' doesn't appear.
I try a solution found "php.validate.excecutablePath" and I did not have results.
Finally I tried installing again VS Code after uninstall and delete all but doesn't work.
I don't know what to do.
I know it's very late lmao, but here's what I found; In order to make the setting re-appear, uninstall any extra php related extensions and restart vscode (you might also want to disable and re-enable php through searching "#builtin php" in extensions). That should bring the option back; then go and set up the path in the settings.json, and if you are a windows user add it to your environmental variables (specifically path).

How to use VSCode to remotely edit website files?

I need to be able to remotely log into web servers for my clients and edit code remotely. I mostly use this for CSS changes, but also am starting to play with PHP as well.
I have tried to get Remote-Editor to work but it won't pick up the .remote file that I placed in the /home folder. The instructions don't really give great details on setting this up.
What do I do?
Use FileZilla, then set VScode as default editor (edit->settings->file editing->filetype associations and insert "php /usr/bin/code"). okey, now u need select your file on FTP and press "View/Edit", then ur file open in VScode editor. Done:)
Use an FTP client (like FileZilla), then set VSCode as the default editor. Anytime you open a file, it will open it in VSCode. I highly recommend that you download all of the code to your own computer and use it as a dev environment, and then, when you're finished with your changes, backup your site, then upload the modified files together. It's not required to edit files on your own machine, but it is recommended if you ever need to revert to an old version for whatever reason (like you made a mistake in the code, and now nothing works right).
Alternatively, you can use an extension like FTP Sync to code locally, and have the files be automatically synced for you.
Open Filezilla -> Edit -> Settings -> File Editing -> Filetype associations
Now you will have "Custom filetype associations:" situated on the right pane of the window.
Over there you have to write the command for opening VSCode for PHP files.
Step 1: Search and locate the VSCode Exe file setup install directory on your computer. In my case it was (C:\Users\Shubham\AppData\Local\Programs\Microsoft VS Code/Code.exe)
Step 2: Copy the directory path link of the ".exe" file and come back to the "Custom filetype associations:" inside Filezilla.
Step 3: Now type "php" then give space & paste the directory path that you have copied inside double quotes and then again give space and write "-open". The final code should look something like this
php "C:\Users\Shubham\AppData\Local\Programs\Microsoft VS Code/Code.exe" -open
Step 4: Click the Okay Button and have a coffee.
There are several approaches to this that are all editor-agnostic.
First, there is sshfs, which is cross-platform and you can install via your OS package manager. A simple approach would be as following:
mkdir -p ~/mnt/server
sshfs user#server.example.com:/path/on/server ~/mnt/server
Afterwards, you have the complete folder structure from server.example.com locally available at ~/mnt/server. Make sure you set up SSH keys to avoid entering the user password every time. You can find tutorials on that everywhere on the net.
For servers that only offer FTP access (shared hosting and the like), you can use curlftpfs in the same fashion.
To close the connection, simply unmount:
umount ~/mnt
For a GUI-based approach, you have several options. There is Transmit (macOS), which features mounting connections as volumes, Forklift (macOS) which is a Finder replacement that can do the same, ExpanDrive (macOS/Windows) and my favorite Mountain Duck (macOS/Windows).
If you plan to move lots of data, especially a lot of small files, Mountain Duck performs the best in my experience.
Just type this is Filezilla Settings->File Editing-> File Association
php /snap/bin/code
Open Filezilla and go to Edit >> Settings
Click on File Editing, and set the radio button to use Custom Editor
In the text field below you need to enter the full path to Visual Studio Code, this is usually found in the /usr/bin/ directory, so you need to enter the following /usr/bin/code
Next select the radio button Always use default editor and click OK to finalise the settings.
Most of the answers I see are for Windows. If anyone wants to associate File Types using Linux in Filezilla, the path is a bit different.
htm /snap/bin/code --force-user-env --no-sandbox --unity-launch
html /snap/bin/code --force-user-env --no-sandbox --unity-launch
js /snap/bin/code --force-user-env --no-sandbox --unity-launch
php /snap/bin/code --force-user-env --no-sandbox --unity-launch
You do not need to use the extra flags, but they are being used in the Menu Shortcut, so I included them.
To set VS Code as default editor for all type of files in mac use below steps:-
Click on Edit menu
Then click on setting option
Then find out File Editing and click on it (Not on submenu(Filetype associations))
Click on custom editor and then browse in application or download and select VS Code. And also click on checkbox "Always use default editor" and then click ok.
open filezilla->edit->file editing->use custom editor->browse(find the visual code path)
for find visual code path->right click on the visual code and open location and paste that location to the browse menu and find the visual code short cut
after that press ok on filzilla it will work fine
It's important that you start Filezilla as an administrator. That was the reason why it wasn't working for me.
Open Filezilla -> Edit -> Settings -> File Editing -> Filetype associations then type:
php "C:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\Code.exe" %f
Note: substitute <username> with your windows username
Bonus: php can be replace with any kind of file format. Just write file extension name on lowercase.
I used this registry update to set vscode as my default text file editor (copy & paste into update.reg, open regedit and import the file):
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\SystemFileAssociations\text\shell\edit\command]
#=hex(2):22,00,25,00,55,00,53,00,45,00,52,00,50,00,52,00,4f,00,46,00,49,00,4c,\
00,45,00,25,00,5c,00,41,00,70,00,70,00,44,00,61,00,74,00,61,00,5c,00,4c,00,\
6f,00,63,00,61,00,6c,00,5c,00,50,00,72,00,6f,00,67,00,72,00,61,00,6d,00,73,\
00,5c,00,4d,00,69,00,63,00,72,00,6f,00,73,00,6f,00,66,00,74,00,20,00,56,00,\
53,00,20,00,43,00,6f,00,64,00,65,00,5c,00,43,00,6f,00,64,00,65,00,2e,00,65,\
00,78,00,65,00,22,00,20,00,25,00,31,00,00,00
After that the registry is updated as follows:
Of course you should not trust hex encoded registry updates you found in the internet. So copy 22,00 ... 00,00, remove all backslashes, linebreaks and whitespaces and convert through one of many hex to ascii online converters to verify the import:
After you made this change you can even edit text files with vscode through the "edit" context menu entry:

Cannot get browscap to load on OSX no matter which version I use or where I put it

I am trying to get the following code to run:
$browser = get_browser(null, true);
print_r($browser);
The error that I get is as follows:
Warning: get_browser() [function.get-browser]: browscap ini directive not set in /Applications/XAMPP/xamppfiles/htdocs/series/firstfile/index.php on line 3
I am running OSX 10.8.4 with XAMPP. The browscap info in my php.ini file is as follows:
[browscap]
;browscap = /Applications/XAMPP/xamppfiles/etc/browscap.ini"
I have also tried the following paths:
/Macintosh HD/Applications/XAMPP/xamppfiles/etc/browscap.ini
I downloaded and placed the browscap.ini file myself into that directory and have also tried referencing it from other locatations in case it was a permission issue or something.
I am assuming that the problem is with how I write my path but I just cant find a way to get XAMPP to accept it and when you go to phpinfo() it is listed under 'core' as browscap - no value.
Obviously I have been restarting Apache etc. with each change to ensure that the php.ini is refreshed.
All of the information I can find seem to pertain to Windows rather than Mac so I am struggling!
I wonder what kind of valuable information you expect to get from this function.
But whatever it is, please be advised that it is considered bad practice, because you are essentially practicing server based client sniffing, and the only base of information is the user agent string, which can be anything and does not need to represent the real situation. Also, information like "javascript" can only represent the coded ability of the client, not the current configured abilities, which can be less.
If you still think the function to be of any use, you have to solve the task of getting a copy of that "browscap.ini" file this function wants to use, and you have to constantly update this file to include new browser versions.
There is a link to a file source on the documentation page of get_browser(). Download a file and point the INI setting to that location. Make sure to activate it by removing the semikolon.
I gave you the instructions to solve your problem,I think this will help you. your file path was absolutely right but you forgot to remove the semicolon and the double quotations mark [browscap]
;browscap = /Applications/XAMPP/xamppfiles/etc/browscap.ini"
download the file by clicking the link and put it in the file path which I explains you below
http://tempdownloads.browserscap.com/stream.asp?PHP_BrowsCapINI
Yeah, it seems XAMPP on Mac OSX installs differently, and you don't specify the root directory. First, find the file 'php.ini' installed in the following location: /Applications/XAMPP/xamppfiles/etc/php.ini Second, 'php.ini' is write protected in this location, so copy it to desktop thus allowing you to alter it. From desktop open in TextEdit and look for text reading '[browscap]' (we'll come back to this). Third, download a copy of file 'php_browscap.ini' from the Browser Capabilies Project.
Mac OSX (cont.) Fourth, change filename from 'php_browscap.ini' to 'browscap.ini'. Place a copy in the following location:** /Applications/XAMPP/xamppfiles/etc/extra/browscap.ini Fifth, now go back and update file 'php.ini' with the new location of 'browscap.ini' to read as follows: [browscap] browscap = /Applications/XAMPP/xamppfiles/etc/extra/browscap.ini Sixth, save 'php.ini' and copy from desktop back into original location: /Applications/XAMPP/xamppfiles­/etc/php.in
Seventh, restart XAMPP. ** Note: I think the location of 'browscap.ini' may be somewhat arbitrary. What seems most important is the pathname that is listed in file 'php.ini' under [browscap] (in my case, browscap = /Applications/XAMPP/xamppfiles­/etc/extra/browscap.ini). Good luck fellow Mac XAMPP users!

How to add a custom file extension that has a dot (blade.php) in NetBeans?

I need to assign a custom extension to be recognized as a twig file in netbeans ('blade.php' as 'twig' file and give me syntax highlighting and code completion appropriately). The problem with using the File association option (in Tools > Options > Miscellaneous > Files)
is that it won't let me add '.' in extension like blade.php, it works with single worded extensions like php, html, css etc.
Will be grateful if anybody can help me with this!
Workaround I figured out and seems to work (at least Netbeans 8.x+)
Go to Tools > Options > Miscellaneous > Files
Click New
Enter blade as the new extension (you can use anything here, but this seems the most natural)
Click OK
In Associate File Type (MIME) select TWIG (text/x-twig)
Click OK of the whole Options window
Close Netbeans
Open the Netbeans configuration folder - on Windows it's %AppData%\Netbeans\<version>\
Go to subfolder config\Services\MIMEResolver
Open user-defined-mime-resolver.xml
Find the <ext name="blade"/> entry (or whatever you entred above)
Change the blade to blade.php
Save and close the file
Voilà, higlighting should now work in Netbeans IDE :)
Modify the user-defined-mime-resolver.xml file so that it looks something like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE MIME-resolver PUBLIC "-//NetBeans//DTD MIME Resolver 1.1//EN" "http://www.netbeans.org/dtds/mime-resolver-1_1.dtd">
<MIME-resolver>
<file>
<ext name="php"/>
<name name=".blade" substring="true"/>
<resolver mime="text/x-twig"/>
</file>
<file>
<ext name="php"/>
<resolver mime="text/x-php5"/>
</file>
</MIME-resolver>
On Linux (Ubuntu), you can find this file at:
$HOME/.netbeans/8.2/config/Services/MIMEResolver/user-defined-mime-resolver.xml
On Windows, you can find the file at:
%AppData%\Netbeans\8.2\config\Services\MIMEResolver\user-defined-mime-resolver.xml
Basically, the first <file> block scans the filename of any PHP files to see if it contains the ".blade" substring. If so, the file is treated as a Twig file. If not, the second <file> block will treat the file as a normal PHP file.
You might need the "Twig Templates" NetBeans plugin in order to get proper highlighting:
Tools > Plugins > Available Plugins > Twig Templates
It's not perfect... Blade directives such as #include are still highlighted as plain text. However, I feel it is a marked improvement over PHP syntax highlighting.
The following sources were extremely helpful:
HOW TO: Declarative MIME Type Resolvers
DTD Grammar Documentation
David Benedeki's earlier answer to this question
A lot of people are developing on other systems, as I am on Centos 7, so this workaround almost worked.
For CentOS, and probably other systems as well, follow these steps, almost the same as above for Windows:
Open Netbeans. Go to Tools->Options->Miscellaneous and select tab Files.
In File Extension row, click New button. Enter crazywrongname as extension name (this is important for option 2)
Below that, under Associated File Type (MIME): choose the option TWIG (text/x-twig)
click Apply and then OK.
Close Netbeans
Option 1:
The following steps are for CentOS 7 and NetBeans 8.1, most probably for other systems as well, but if you can't find the file at that path, option 2 is below.
open Terminal and open the file /root/.netbeans/8.1/config/Services/MIMEResolver/user-defined-mime-resolver.xml in your favourite text editor, e.g. run command nano /root/.netbeans/8.1/config/Services/MIMEResolver/user-defined-mime-resolver.xml
find the parameter name "crazywrongname" in this file and change it to "blade.php"
save the file
open Netbeans and enjoy.
People from the future, you might try changing the Netbeans version in file path from option 1 to yours, like 14.3 or whatever is out in 2028.
Option 2:
If you can't find this file in the exact path as above, run this command to find it:
cd / && grep -rI --exclude-dir=proc --exclude-dir=sys crazywrongname *
This will start a search for the specific pattern on your whole system, starting at root. That's why we named the parameter crazywrongname - so it isn't found in any other file on the system, like blade would be. It will also exclude the folders that are not supposed to be accessed. If you don't exclude them, you will get errors and possibly hang your system. Also, some pink unicorns might die.
After you find the exact file path for your system, follow the remaining steps in option 1 for changing the parameter name.
Thank you, mysterious David Benedeki who disappeared from StackOverflow after answer which helped enormously :)
As I can see the problem is more NetBeans-centric, so I would also suggest you to file a bug report to the NetBeans community.
The NetBeans forums.
The NetBeans bug tracker.
Maybe in the future they can fix that issue. You may also link that question so they can see the user reactions.
For module development with custom *BladeDataObject file
#MIMEResolver.Registration(
resource = "BladeResolver.xml",
displayName = "#LBL_Blade_LOADER"
)
and in the same package create the BladeResolver.xml file with the content
<MIME-resolver>
<file>
<ext name="php"/>
<name name="blade" substring="true">
<resolver mime="text/x-blade"/>
</name>
</file>
</MIME-resolver>

Including different types of files in PHP

I took over a PHP project and I'm trying to get it running on my dev box. I'm a developer and not a sysadmin, so I'm having trouble getting it working.
The previous developer used .h files to include PHP. My current configuration is taking that .h file and including it without executing it. What do I need to look for in my apache config (or is it my php.ini)?
EDIT:
Something clicked when I read one of the comments below. The code is using ASP style tags "<?". I've turned the option on in php.ini and according to phpinfo(), it's enabled, but apache is still just including the code as text.
I just checked it and running the code with the full opening PHP tag "<?php" fixes the problem. Having said that, I'd still like it to work the other way.
I'm running the code on a Macbook with the latest versions available. PHP 5.2.6, postgresql 8.3 and apache 2.
The code works on the staging server, but I can't figure out what the difference it.
EDIT
Durrr...I didn't have short_open_tags enabled in php.ini.
Could the problem be that the .h file you are including just starts into php code without the opening "<?php" tag?
From include documentation:
When a file is included, parsing drops out of PHP mode and into HTML mode at the beginning of the target file, and resumes again at the end. For this reason, any code inside the target file which should be executed as PHP code must be enclosed within valid PHP start and end tags.
PHP is an interpreted language, so you can't 'include' a file without executing it. Remember that '.h' is just a file extension, so although the previous coder may have put PHP in a '.h' file, it's still just PHP.
More details on the problems you're running into would be helpful.
you can use a .htaccess file and add:
php_value auto_prepend_file /path/to/include-file.h
Edit
I've just read that .htaccess only works with the module version of php.
You should change them all to .php extensions. But, if you are going to leave them as .h, you change the mapping in Apache. It's Apache that runs the file through the proper interpreter, not PHP. The PHP engine will process anything passed to it.
include and require will execute the included file. If you are using readfile, it simply echoes the file without treating it as PHP code.
If the .h files are "missing" the <?php directive, then you may have to switch from include to something like:
eval( file_get_contents("file.h") );
Personally I try to avoid eval whenever I can, but sometimes there is just no choice.

Categories