Opencart images not showing after manual import - php

I have the following problem - I am migrating website database from other platform to Opencart.
When I imported the images in oc_product using PHP, they are not showing in the website. The real issue is that if I manually change or type the image path, it works. Maybe it's some cache problem, but I cannot figure out why.
The images are not showing even in the admin panel - attaching picture
Here is also how my database look like - the image path is correct
My Opencart version is 1.5.6.4
Any ideas?

obviously, the image path differs for the images, when we import and thus the imagepath has to be taken care before we actually import the data.And after importing then we have to run a sql query to change the imagepath in the database.

In the question you mention an import step performed using php.
I'm doing a wild guess but maybe that for whatever reason some unprintable character has been added and is messing up the whole thing.
The easiest way to check if this is the case is to analyze the html produced to verify if there is anything odd in the img tag path.
Another quick check is to export a few rows of data that are currently acting weird and analyze the content with a smart (that show special chars) text editor.

Related

Issue converting to .pdf a merged .docx file that opens fine in Word

So, I have the following scenario.
I am working on a system for academical papers. I have several inputs that are for stuff like author name, coauthors, title, type of paper, introduction, objectives and so on. I store all that information in a database. The user has a Preview button which when clicked, generates a Word asynchronously and sends the file location back to the user and that file is afterwards shown to the user in an iframe using Google Doc Viewer.
There's a specific use case where the user/author of the paper can attach a .docx file with a table, or a .jpeg file for a figure. That table/figure has to be included inside the final .docx file.
For the .docx generation process I am using PHPWord.
So up until this point everything works fine, but my issues start when I try to mix everything and put together the .docx file.
Approach Number One
My first approach on doing this was to do everything with PHPWord. I create the file, add the texts where required and in the case of the image just insert the image and after that the figure caption below the image.
Things get tricky though, when I try doing the same thing with the .docx table file. My only option was to get the table XML using this. It did the trick, but the problem I ran into was that when I opened the resulting Word file, the table was there, but had lost all of its styling and had transparent borders. Because of those transparent borders, afterwards when converting it to PDF the borders were ignored and the table info is just scrambled text.
Approach Number Two (current one)
After fighting with Approach Number One and just complicating stuff more, I decided to do something different. Since I already generated one docx file with the main paper information and I needed to add another docx file, I decided to use the DocX Merge Library.
So, what i basically did was I have three generated word files, one for the main paper information, one for the table and one for the table caption (that last one is mainly to not overcomplicated the order of information). Also, that data is not in the table .docx file.
Then I run this:
$dm->merge( [
'paper-info.docx',
'attached-table.docx',
'attached-table-caption.docx'
], 'complete-file.docx');
So, afterwards, I check and the Word file is generated just as I need it with the table maintaining its original styles and dimensions.
If I open it in LibreOffice though, I get this error message:
Then if I continue and open the file, the file opens correctly with all the data with the only exception that it no longer respects the fonts of the file as they appear in Word.
So, the problem comes in the next step. Since I need to present a preview of the file using Google Doc Viewer using this syntax:
<iframe src="https://docs.google.com/gview?embedded=true&hl=es_LA&url=https://usersite.net/complete-file.docx?pid=explorer&efh=false&a=v&chrome=false&embedded=true" width="100%" height="600" style="border: none;"></iframe>
The document gets loaded fine, but when I review it what I see is that it only shows the content of the first paper-info.docx file and ends right where the table and table caption should appear. I open the exact same file in Word and it shows the table and caption.
The other issue is when I try to convert the file to PDF.
If I use PHPWord's method of conversion in combination with DomPDF I get the exact same issue as with the Google Docs Viewer, I just have the content of the first file, using this code:
$phpWordPDF = \PhpOffice\PhpWord\IOFactory::load('complete-file.docx');
$xmlWriterPDF = \PhpOffice\PhpWord\IOFactory::createWriter($phpWordPDF, 'PDF');
$xmlWriterPDF->save('complete-file-pdf');
So my only other viable route was to use LibreOffice's command line using this command:
soffice --headless --convert-to pdf complete-file.docx
This converts the file correctly, but has the issue mentioned when trying to open the .docx file in LibreOffice, the font styles are disconfigured.
Also weird part is that if I try to run this in my PHP script:
shell_exec('soffice --headless --convert-to pdf complete-file.docx');
Nothing happens.
I am running Apache 2.4.25, PHP 7.4.11 on Windows 10 x64.
Conclusion
Until now my best result was by merging the files, but it also caused this issue. So maybe the issue is coming from the merging process I am using. What would be ideal is to be able to just insert the table with styles and everything using PHPWord, but I haven't been able to and haven't found any examples on how to do that.
Another option that I've seen is this library, but the merge features is only in the license that's $599 USD, and since I am pretty close to solving this, I am not sure if it would solve my issue. If it does, I'd invest in it since I need to get this done ASAP, but I wanted to check with you guys what your recommendations would be for this case. Maybe another merging library or doing everything via PHPWord.
Help is appreciated!
After a lot of attempts to fix it, I wasn't able to achieve what I wanted with PHPWord and the merging library I mentioned.
Since I needed to fix this I decided to invest in the paid library I mentioned in my question. It was an expensive purchase, but for those who are interested, it does exactly what was required and it does it perfectly.
The two main functions I required were document merging and importing of content to a .docx file.
So I had to purchase the Premium package. Once there, the library literally does everything for you.
Example for docx files merge code:
require_once 'classes/MultiMerge.php';
$merge = new MultiMerge();
$merge->mergeDocx('document.docx', array('second.docx', 'other.docx'), 'output.docx', array());
Example for how to import a table from another docx file
require_once 'classes/CreateDocx.php';
$docx = new CreateDocxFromTemplate('document.docx');
// import tables
$referenceNode = array(
'type' => 'table',
);
$docx->importContents('document_1.docx', $referenceNode);
$docx->createDocx('output');
As you can see it is pretty easy. This answer is by no means an ad for this library, but for those that have the same problem as me, this is a life saver.

Tinymce wiris plugin image mode issue

I am using tinymce wiris plugin for entering equations for my project. Everything is working.
The equation I entering is previously saving as MATH ML format. It had some issue in chrome. So, I had to use mathjax for fix this issue. One of the project requirement was generating doc files. It also working fine except the math-ml equation. special characters are showing the doc file instead of the equation.
I googled and found that this the wiris have a imagemode option for saving the equation as image instead of MATH ML. It worked well in chrome. But still a broken image is showing in the doc file instead of equation image. Then I checked the
plugins/tiny_mce_wiris/integration/showimage.php?formula=4ee7dd91304079fd072d156593cce168&cw=95&ch=42&cb=23.
I checked the wiris and found that a png image is saving in the cache folder while creating the issue. I am guessing instead of the above showimage.php? script link as src, it is better to show the link of the generated png image.
Unfortunately I am not able to crack that part.
Please help if you have any ideas for that.
Thanks in advance

Moodle: Files uploaded via File API get corrupted when viewed

So I am developing a new course-format, in which a picture is associated with each activity in a course, and presented visually. I created the course format, overrode the renderer etc. That worked all fine. However, the images are supposed to be custom generated and since it has to work for all existing and future, I put some additional code into the general course module form, enabling an image upload.
After admittedly some struggle on my part to get the File API working, it now all works fine. Only in my course format, there is an additional heading, under which you can upload a single image. This gets saved to the database fine, it is not in draft and it is viewable in my dataroots filedir perfectly if I follow the contenthash in the database. It even gets loaded into the form as a default fine. However, if I try to work with the image, all tests run fine (.is_valid_img()etc) and I even get offered to download a file. However, when I do it is corrupted and my file viewer says: "Critical Error: Not a png file". Needless to say it is not displayed on my actual course site.
When I look at the file in filedir, it very clearly is a png. Please, I would be thankful for any help, since I have tried alot and am at my wits end.
It sounds to me like you are getting some sort of output on the page before the PNG file is sent - that would be added to the start of the file and cause it not to work as a PNG file.
I would suggest you open the file in a hex editor and check the start of the file - it should look like https://en.wikipedia.org/wiki/Portable_Network_Graphics#File_header, so look for extra characters before that.
As for where the extra characters come from - they may be an obvious warning / error message (which should be easy to track down and fix). Alternatively, you may have some stray 'echo' statements (again, fairly easy to track down). The worst problems to find are extra characters before the opening 'php' tags of a file somewhere in your install or after the closing tag at the end of a file (which is why you should never use closing PHP tags). Finding these will come down to searching through all your customised code files to locate them.

I need help about strange files, I want to get data from these files with php (or suggest) and send it to MySQL

Here are the files:
1) In this website:this has excel file, sized 4kb only, that I can't edit, and when I try to get data from it with php, it says that this file is "read only" when it's not. This is price list from accounting program.
2)In this website: is where the program saves the data I think so, but it's coded.
Any suggestions?
i try with all php excel reader i found in net :) i am using win 7, working with xampp in local.
problem is that, i think, that excell file is protected or something, it is exported from program.
i need to get data from that excell file or from another . rea file, they consists data about products : quantity, price, name and so, i can manually add all products to the site, but its better to get data from that program and automaticaly do it, and when there are changes in program it reflects on the site automaticaly, thx for the answers

Best way to store and deliver files on a CMS

First of all, this isn't another question about storing images on DB vs file system. I'm already storing the images on the file system. I'm just struggling to find a better way to show them to all my users.
I' currently using this system. I generate a random filename using md5(uniqueid()), the problem that I'm facing, is that the image is then presented with a link like this:
<img src="/_Media/0027a0af636c57b75472b224d432c09c.jpg" />
As you can see this isn't the prettiest way to show a image ( or a file ), and the name doesn't say anything about the image.
I've been working with a CMS system at work, that stores all uploaded files on a single table, to access that image it uses something like this:
<img src="../getattachment/94173104-e03c-499b-b41c-b25ae05a8ee1/Menu-1/Escritorios.aspx?width=175&height=175" />
As you can see the path to the image, now has a meaning compared to the other one, the problem is that this put's a big strain in the DB, for example, in the last site I made, I have an area that has around 60 images, to show the 60 images, I would have to do at least 60 individual query's to the database, besides the other query's to retrieve the various content on the page.
I think you understand my dilemma, has anyone gone trough this problem, that can give me some pointers on how to solve this?
Thanks..
You could always use .htaccess to rewrite the url and strip the friendly name. So taking your example, you could display the image source as something like:
/Media/0027a0af636c57b75472b224d432c09c/MyPictures/Venice.jpg
You could use htaccess to actually request:
/Media/0027a0af636c57b75472b224d432c09c.jpg
The other option is to have a totally friendly name:
/Media/MyPictures/Venice.jpg
And redirect it to a PHP file which examines the url and generates the hash so that it then knows the actual image file name on the server. The php script should then set the content type, read the image and output it. The major downside of this method is that you may end up with collisions as you two images may have the same hash. Given that the same thing can also occur with you current method I assume it isn't an issue.

Categories