Multipart upload inside PHPUnit test - phpunit

I am trying to make a multipart post request inside PhpStorm. I want to upload a file. I have inside function:
$this->post($uri, "[]", $this->setMyHeaders());
But where to put file in.

Related

How to access html file inside iframe in production

I am creating a web app where, this app will generate a .html file in public/ directory. And after that i want to show that generated html file on a page using iframe .
I am using NextJS for this task. I have configured next.config.js for rewrites but getting 404 error. I am using Railway for hosting. Since in Vercel we can not access filesystem here.
Instead of generating html dynamically, if I upload that .html file, then i can access that file using iframe in production.
I think we can not access those files which were not available during build process. (this is my guess , maybe wrong)
How can I solve this problem or should I use another framework ?
Thanks
Since I was accessing .html files (i.e <iframe src="path-to-file"></iframe>) which were not available during build process, that's why i was getting 404 error.
So I did the following thing:
suppose I want to do this <iframe src="/pdf/page01.xhtml"></iframe> where file location is in public/pdf/page01.xhtml.
so this src is sending a GET request to localhost:3000/pdf/page01.xhtml.
To manipulate this request I created a pages/api/pdf/[...slug].js. In this file you can use process.cwd() to access the file inside your public dir. You read file content using fs.readFile and send the response res.status(200).send(data) like this.
By doing this I was getting the desired result.
Suggestions are always welcome.

Insert Image from Symfony path with PHPExcel

I'm trying to insert images in my Excel using the PHPExcel_Worksheet_Drawing of PHPExcel (in this Symfony Bundle) but I get this message all the time:
File http://benefest.local/uploads/persons/image/58af244d3f58c_16143190_10210682923503464_8658615512523719175_n.jpg not found!
Here is my code:
$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setPath($path);
$objDrawing->setWidth(30);
$objDrawing->setCoordinates('A1');
$objDrawing->setWorksheet($phpExcelObject->getActiveSheet());
My images are uploaded by VichUploaderBundle, and I'm generating the absolute path through a function. which returns me http://benefest.local/uploads/persons/image/58af244d3f58c_16143190_10210682923503464_8658615512523719175_n.jpg
In a browser, this image is displayed!
Any clue?
Answer is based on my comments to this question.
There is a difference between URI and file path:
URI - used in browser, or being more general in HTTP protocol to get access to some resource via web-server
File path - a link to some file within filesystem on your server/computer/etc.
Your function returns a URI string (http://benefest.local/uploads/persons/image/58af244d3f58c_16143190_10210682923503464_8658615512523719175_n.jpg), which can be used to access the image via a web server.
But PHPExcel_Worksheet_Drawing as well as other libraries use PHP's filesystem functions to get access to some file locally. So you need to get a local file path, instead of URI (in you case it is ./uploads/persons/image/58af244d3f58c_16143190_10210682923503464_8658615512523719175_n.jpg).

How to define Wordpress global variable for use in a REST Controller?

I'm extending the WP REST API by writing a Controller class.
I'm trying to read the config for this class from a file, e.g:
{
"base-namespace": "myapi",
"version": "v1",
"resource": "things"
}
This would allow me to keep server and client in sync as they would both use the same config file.
However, I do not want WP to stay reading this file for every request it serves... Currently, if I read this file from anywhere in the plugin file (or any of its required files - including the Controller definition), and if I also echo out where I'm reading, I see it's always passing through that bit of code (including the reading) for every request.
I imagine I need to read this file somewhere outside the plugin itself - make it a global, and then access it when instantiating the Controller.
I'm new to WP - this is the first time dabbling with it. Where should this global variable definition go such that it's only executed once?
Note:
I have tried using require_once in my plugin to require a config file which does the file reading. I had put an echo statement there and it shows that that file gets executed for every request (despite the require_once).
I have also tried wrapping the file reading in an if(!isset($my_global_var) statement. But adding an echo statement inside the if statement shows that this global variable is always unset with every request served... clearly this needs to go in some kind of WP startup file which only gets executed once.
Thank you.
Store your config data as a PHP array in a .php file and then include it using the PHP include statement. Advanced PHP engines parse the PHP source once and cache a compiled representation of the script so that it does not have to re-parse the PHP sources everytime. So if your data is inside a PHP source file it would be saved in the PHP's engine compiled script cache.
Of course if your client is non-PHP it would need to have code to parse a PHP array.

Send file with Postman to FosRestBundle Symfony

Im trying to upload file to a Symfony app, then retrieve the file from the ParamFetcher of FosRestBundle, finally create a SonataMedia object with the uploaded file.
Im stuck on how to upload the file. The entire application has been developed using Postmans POST, GET, DELETE, etc functions for testing right until now.
If already tested as shown in the picture, simply doing a POST with de param file having the image file selected. ParamFetcher is not detecting the param and returns error message saying file is null.

Ioncube: Is it possible to encrypt an specific function within a PHP file

I have a file called sample.php, that file has PHP and HTML code. I only want to encrypt the PHP function within that file using ioncube. Is it possible?

Resources