Before I describe the problem, here is a basic run-down of the overall process to give you a clearer picture. Additionally, I am a novice at PHP:
I have a WordPress website that uses CPanel as its web hosting software
The WordPress website has a form (made by UFB) that has the user upload an image
The image gets directed to the upload folder (/uploads) by using image_upload.php
The image is then downloaded onto a computer, and a program is run which generates numbers about the picture(the number generator program is in python)
After the numbers are generated, it calls on report.php and template.xlsm
Report.php gets those generated numbers and then puts them into their designated places on the xlsm file
The xlsm file is then converted into a pdf, which is then emailed to the user that submitted the picture.
I inherited all of this code from someone else who wanted me to help them on this project. Here is my problem:
I don't understand how the PHP files are being called. I have python code ready to run the number generator online, however, I can't do this without figuring how the PHP files are being called.
I understand what the PHP files do, I just don't understand how they are being called. I tried doing a -grep search for both image_upload.php and report.php, but I come up empty. There aren't any other PHP files that seem to do an include(xyz.php), which is supposed to be how PHP files are called. I don't understand what calls image_upload.php to get the pictures moved into the /uploads folder. I also don't understand what calls report.php to make it run. I tried looking in functions.php, where most of the other PHP files are called, but report.php and image_upload.php aren't.
Please help me! If any clarification is needed, just comment, and I will try to provide any help I can!
An easy way to get the the calling functions (including include and require calls) from any point in your PHP scripts is to get the stacktrace:
$e = new Exception();
var_dump($e->getTraceAsString());
You can also use an logger instead of the var_dump.
Unfortunately a simple grep for requires and includes won't suffice for a large project like WordPress due to the use of autoloading:
https://www.php.net/manual/en/language.oop5.autoload.php
While this resource isn't specific to your project, and things could be setup drastically different in your project, I think the details here may provide enough hints about autoloading to get you started in the right direction to understanding things in more depth:
https://wordpress.stackexchange.com/questions/212153/using-spl-autoloading-within-wordpress-plugin
Related
I need to add some custom fonts to TCPDF library, yet after surfing internet for hours, I couldn't come up with a nice working solution.
Generally two main ways are offered to create new fonts for TCPDF library. One is using online websites doing the conversion; the other is using tcpdf_addfont.php and more specifically addTTFfont method.
With the first way, there is a great stumbling block as the most famous website doing the job is now down: that is fonts.snm-portal. In fact, it is not down, yet does not do the previous conversion task any longer. The second website that is xml-convert just produces .php and .z files and totally ignores .ctg.z. I guess, my custom files are not being recognized without this .ctg.z extension available.
For the second way, I really couldn't do anything special, as I don't know much about terminals. I just opened the path and copied the code:
./tcpdf_addfont.php -b -t TrueTypeUnicode -f 32 -i blah.ttf
yet, nothing special happened. This code just opened up the tcpdf_addfont.php file in the IDE, and no font files were created in the fonts folder, as it is supposed to do; There is something wrong here with this command line, as when looking inside the php file, one can make sure that in case everything goes fine, there must at least be some echoing, whether to show an error, or to confirm that the files have been created. Yet, nothing shows up and instead running the code in Powershell opens up tcpdf_addfont.php in my php IDE. That's the whole story. With this introduction in mind, may you please let me know how I can get .ctg.z file for the custom fonts, whether via the first method or the second. Any help would be welcome.
THANKS in advance.
I will go straight to the point,
i was thinking of using dropbox as a file sharing system for some files that i am distributing through my website. So after some research and some hours of reading the documentation, i am now able to upload, generate links and share my files from my PHP built website. So far so good.
Now lets go to the problem.
The files that i am uploading/distributing are the same for every member with an exclusion of one file (license.txt) which needs to be different on every member.
So to solve this problem i came up with one idea, i will open the ZIP file through PHP and the core side of my server, add/replace the license.txt file, ZIP it again and upload it. Yeah that works like a charm but guess what? Its a 80mb file and takes more than 4 minutes to complete the whole process which is something i want to avoid.
So to make it much faster i came up with another idea. My idea was to distribute the files directly from the dropbox un-zipped by duplicating the root folder (of the APP). So the whole process was really simple, firstly an API call to duplicate the root folder (the one that was containing the files), then another one to upload only the edited license.txt file on the new duplicated folder and one last API call to generate the share link. It worked really well and much faster on my tests, but when i finalized my code and tried it live, it turned out to be a disaster since i got an error "too many files".
So my questions is, if there's any way to touch somehow remotely zipped files on dropbox. I saw that the browser can OPEN without problem any ZIP file and show all the contained folders.
Am i missing any possible solution? Any advice would be more than appreciated.
Okay so I have a joomla site that uses a compponet that is used to create events or booking times. My problem is I can't find the form file that I am trying to access within my joomla administrator componets directory for the com of that plugin. Here is the URL of that form makeanappointment/create?dtstart=201404250930&cal_id=5
So my question is is there a script I can run in PHP to find out all those files being called in and their location?
David
Theres a PHP function called get_included_files() which returns a list of all files that were loaded via include, include_once, require and require_once.
It may be a bit primitive for what you are looking for (it doesn't have the caller line numbers etc), but it will at least show you all the files used during a particular execution. Just add a call to that function near the end of the main script.
Since it returns an array you'll probably need to dump the contents (i.e. print_r(get_included_files()).
See the get_included_files() manual page on php.net for more usage details.
When looking for a particular source file, I usually expand the extension installation file on my local machine and then use a search utility to find instances of text used on the web page.
Once I can find the correct source file on my local machine, it's usually fairly easy to find the file on the website.
What I have to be able to do is copy an entire folder from a remote source to the local server executing the PHP file. I can do that fine except for one problem, PHP files. Obviously, I can't just go copying the source code of a PHP file using regular commands as they will interpret the code and give me the returned stuff. What I have to have is the code. Is there any way to do that?
Hope I'm clear enough, my problem isn't something very hard to understand, I just want to know if it's actually possible. If not, maybe someone may have an idea of an optimal way of storing the source code alongside the executable php? I was thinking simply saving it as text when I'm done developing but if there is a way to do it completely automatically then that would be much more awesome. Best case scenario, I can just copy the folder with php files and then execute it from local. I need to know if that's even possible... Worst case scenario, I have to duplicate files in order copy the text version of them to the local server and discard the php ones since th e executed files are not relevant to my program. I don't want that, but I just don't know if PHP is able to do what I want.
Edit: sorry for not specifying! I am the admin of the remote server and have total access. I can and was expecting to make a php file on the server itself. That's the kind of system I have at the moment! I zip a folder and return it when requested from my local source. My only problem is the php executing.
You cannot do that unless you:
have FTP access (or anything else that is not HTTP-based)
have access to a script on the server that is designed to return the sourcecode of a given file
use an exploit such as the ?-s bug in the CGI SAPI
So you are most likely out of luck.
I have a series of web sites all hosted on the same server with different domains. I want to host some common PHP scrips and then be able to call these from the other domains.
Im am a bit fresh with my php so pls excuse code attempts - I have tried iterations of the following which may try and help you understand what I am aiming for!
from within php tags ...
include('http://www.mydomain/common_include.php?show_section=$section');
$show_section = $_GET['show_section'];
include('http://www.mydomain/common_include.php');//Then $show_section would be available to the included file/cod
Finally I have tried pulling in the include which contains a function then trying to run that include from the parent script.
I would much prefer to keep this PHP
orientated rather than getting
involved with the server (file
systems etc (but I can change
permissions etc)
I can but would prefer not to just upload the same library to each of the domains separately
I understand PHP is run on the server hence maybe problematic to include scripts across onto another server.
Thanks in advance.
#
EDIT
OK OK - I get that its bad practice so will not do it....THANKS VERY MUCH FOR THE QUICK ANSWERS.
However is there any other recommendations of how to esentially show this basic php app on all of the sites with out haveing to add the files to the root of each site? Just to prevent massive script duplication...(thinking out loud call the scripts in from a db or anyother soloutions)
Again thanks for your assistance
That would be a huge security risk if you could just include remote PHP files to your own projects. The PHP gets parsed before the server sends it to you so cross-domain includes would only contain the output the script generates. The only way to include PHP files so that they can be executed is via local filesystem.
If you look at PHP.net's documentation about include, you can find this:
If "URL fopen wrappers" are enabled in PHP (which they are in the default configuration), you can specify the file to be included using a URL (via HTTP or other supported wrapper - see List of Supported Protocols/Wrappers for a list of protocols) instead of a local pathname. If the target server interprets the target file as PHP code, variables may be passed to the included file using a URL request string as used with HTTP GET. This is not strictly speaking the same thing as including the file and having it inherit the parent file's variable scope; the script is actually being run on the remote server and the result is then being included into the local script.
Which pretty much explains the whole thing.
The root of the original question seemed to be the poster's concern about using a PHP script or plugin on multiple sites and then having an onerous task each time it needs to be updated. While trying to include PHP files across sites is a bad idea, it is a better plan to structure your script to be as self contained as possible. Keep the entire plugin contained in one directory.... and ensure your function calls to utilize it are as well formed as possible - clean, well named functions, uniform naming conventions and a well thought out plan for what parameters each function needs. Avoid using global variables.
Ideally you should then have quite an easy time each time you need to update the plugin/script in all locations. You can even set up an automated process that will upload the new directory containing the plugin to each site replacing the old one. And the function calls within your code should rarely if ever change.
If your script is big enough you might implement an automatic update process like the more recent versions of Wordpress use. Click a button and it updates itself. In the past, updating a dozen sites running Wordpress (as an example) was a massive pain.
That is very bad practice.
Actually you're including not PHP but just HTML code.
Include files, not urls. It is possible for the same server.
Just use absolute path to these files.
Apart from the fact that it's a bad practice you should first check if include allows URLs if you really want to do that.
If however all the sites that need to use the script, you could put the script somewhere in a directory accessible by the user that executes php and add that dir to the php.ini include_path property (can also be done at runtime)
(Or you could create a php extension and load it as extension)
If you have root rights on that server, you could just use absolute path from filesystem root, but most hostings won't let you do this.