The stylesheet in the html doesn't load

Hi, I’m using the ojs 3.3.0.8 and trying to see and html file with the css, like this
image
but when I look the code file there isn´t any link to the stylesheet. What can I do for see the html with the styles ?

Hi @Nicolas_Aguirre_Espi,

Through adding the CSS file are you able to provide a public facing link that you can then link to in your HTML file - and have you done this?

Also, we have some specific advice in one of our guides for how to go about providing styles for HTML galleys, you may want to have a look at this and follow the advice there: https://docs.pkp.sfu.ca/learning-ojs/en/production-publication#style-html-galley-files

-Roger
PKP Team

The style for the html file load fine when I change in the data base in the table files the mymetipe of text/x-asm to text/css, but I can’t do this process for all the submissions, Do you know how can I fix this ?

Hi @Nicolas_Aguirre_Espi,

Hmm… I’m not sure what would be going on, so others might need to weigh in if they have any ideas.

-Roger
PKP Team

Hi @Nicolas_Aguirre_Espi,

As you already noticed, in your case, PHP doesn’t determine MIME type correctly. I would check if php’s fileinfo extension is installed and working. Also, you can try to uncomment mime_database_path in OJS config file or change path to the one, your server uses.

1 Like

I’ve already try uncomment but doesnt’t work, and I don’t find where can I find the path in the server.

Can you double-check first if fileinfo extension is installed and enabled?

The extension is installed and enabled

As the next step to narrow the problem, I would create a script that checks fileinfo in action: https://www.php.net/manual/en/function.finfo-file.php. It should show the correct MIME type text/css on your CSS file.

Probably, the easiest would be using mime_content_type function, included in this exension: https://www.php.net/manual/en/function.mime-content-type.php, e.g.:

<?php

error_log(mime_content_type('path/to/file.css'));

Will write the MIME type of the CSS file to the php error log after execution.

Also, you could check how your OS determines MIME type, e.g., on Ubuntu from the terminal file --mime-type path/to/file.css works for me. This shows if the problem is on the system configuration level rather than php

When should I run the script, while I make a new submission or in what moment of the process ? Is the script in a specific file or in the terminal ?

Just create a file, say custom.php, with the content above and make a request through the webserver to it. It dumps the result, MIME type of the css file, into the error log.

I don’t know to what extent you control the server but if it’s shared hosting, just put the php and css file to the webroot and make them readable for the web server. Then you can execute by making a request http://www.domain.com/custom.php; check php log and remove files after the test.

If you have access to the command line, you can test how your system determines the MIME type directly, this shows if the problem is on the lower level, I only know the command for Ubuntu which I posted above.

Also, I found a similar thread that looks related: I have an HTML, with a CSS style shee - #16 by asmecher

Hi @Vitaliy , sorry for it took a long time to answer but when I ran the script the files .css appears as text/plain. Do you know what can I do for solver this problem ?

That should be OK, as the code fallbacks to the file extension if MIME type is text/plain, see: pkp-lib/PKPString.inc.php at 902900618f50bc266d9d1afd5c27f88ecb20da79 · pkp/pkp-lib · GitHub and pkp-lib/PKPFileService.inc.php at 902900618f50bc266d9d1afd5c27f88ecb20da79 · pkp/pkp-lib · GitHub
but in your case it’s nevertheless recorded as text/x-asm.
Can you debug the PKPFileService::add() method I’ve linked the latter example, e.g., by placing error_log($mimetype) after line 88 and another one before line 98 and then make a test and upload CSS file? This writes identified extension in the error log.

In the file PKPFileService.inc.php, adding the method no longer allows me to upload new files.
image

How PKPFileService::add() looks right now?
Did you check the error log for the debugging output?

/**
* Add a file
*
* @param string $from absolute path to file
* @param string $to relative path in file dir
* @return int file id
*/
public function add($from, $to) {
$stream = fopen($from, ‘r+’);
if (!$stream) {
throw new Exception(“Unable to copy $from to $to.”);
}
if (!$this->fs->writeStream($to, $stream)) {
throw new Exception(“Unable to write file at $to.”);
}
if (is_resource($stream)) {
fclose($stream);
}
$mimetype = $this->fs->getMimetype($to);
error_log($mimetype);
// Check and override ambiguous mime types based on file extension
if ($extension = pathinfo($to, PATHINFO_EXTENSION)) {
$checkAmbiguous = strtolower($extension . ‘:’ . $mimetype);
if (array_key_exists($checkAmbiguous, $extensionsMap = \PKPString::getAmbiguousExtensionsMap())) {
$mimetype = $extensionsMap[$checkAmbiguous];
}
}
error_log($mimetype);
return Capsule::table(‘files’)->insertGetId([
‘path’ => $to,
‘mimetype’ => $this->fs->getMimetype($to),
], ‘file_id’);
}

Ahh yes, looking at the release 3.3.0-8, it doesn’t have that fallback on the file extension and that might be a reason for the issue. Sorry, no need for debugging, you can remove that.
The best way would be just to upgrade to the latest (3.3.0-11) release.

If you want to try to patch the current one, here’s the issue: CSS file mimetype not correctly recognized · Issue #7344 · pkp/pkp-lib · GitHub and I completely forgot that applied the fix for that. The commit itself is here: Merge pull request #7347 from Vitaliy-1/i7344_stable-3_3_0 · pkp/pkp-lib@7793bbc · GitHub

Let me know if the issue persists after upgrade or patching.

1 Like

Thank you after the patching it works fine, but one question it the same error is happening with the XML files. What should I do ?

Do you mean that MIME type of XML files is different from text/xml? How it’s recognized by your system?

Yes, there is some XML files that doesn’t load