Potmans Olivier
Forum Replies Created
-
Hello Little Package,
Perfect, it works… without using the class WC_Download.
and the solution is really elegant 🙂
Thanks to spend some of your time to help me.Have a good weekend…
Olivier
Hello Little Package,
No problem, this was the same for me, a busy week 🙂
For your first question, yes it works because in your function pdf_download_path, the first argument is the url of the document pdf to download : “http://<url>/wordpress/wp-content/uploads/woocommerce_uploads/<year>/<month>/<filename>.pdf”. So it works because we don’t use the local absolute_path but the remote url.
For the second question:
If this is the line just before the return $file_path
You have an php error because in the section try, you create an object WWPDF_Watermark with the first argument $parsed_file_path[‘file_path’] (received from the method parse_file_path de la classe WC_Download_Handler) that doesn’t contain the local absolute path (drive is missing). So, it’s not possible to “fopen” the origin file.
Seeing that the proposed change is after the try section, there is for me no impactSo for me, the function parse_file_path should send back the local absolute path of the file which enables you to open the file to watermark.
Olivier
Hello “Little Package”,
Far be it from me to criticize anything, I just give time to interesting projects like yours… and troubleshooting is my fun 😉
Yes, you are right, it’s true that the array sent back by the method parse_file_path() of the class WC_Download_Handler contains an item that is not the absolute path in the Windows world. I checked the specifications of the method and it just said that the function “parses file path and see if its remote or local”. So, by just referring to the spec, the method is correct because it determines this is local.
Reason that I proposed that workaround.However, I read that method WC_Download_header (reason of the delay of my answer) and I suspect an error in the end of the method in the else if
elseif ( ( ! isset( $parsed_file_path[‘scheme’] ) || ! in_array( $parsed_file_path[‘scheme’], array( ‘http’, ‘https’, ‘ftp’ ), true ) ) && isset( $parsed_file_path[‘path’] ) && file_exists( $parsed_file_path[‘path’] ) ) {
$remote_file = false;
$file_path = $parsed_file_path[‘path’];
}The first condition tests if there is a drive letter (so detects the “windows world”) but the drive is not added in the $file_path ; working for linux but not for Windows.
the last line should normally be $file_path = ‘scheme’ . “:” . $parsed_file_path[‘path’];
(scheme is the drive letter) and the workaround is not required anymore in your plugin.So, I propose to contact the woocommerce team by referring our discussion about the no-working of your plugin because it seems that the method parse_file_path() of the class WC_Download_Handler sent back an array with a path which is not absolute in the Windows world (drive not mentionned in it). I will ask them if this is a misinterpretation of the specs of their method.
Do you agree with that approach ?
I’m waiting for your approval before contacting them.
Olivier
ps: sorry for the possible mistyping errors, English is not my native language.