Broken file when upload

Broken file when upload

by Fox Jah -
Number of replies: 8

Hi everyone.

I am trying to upload images, but after uploading the image automatically appears broken, when I download the file size remains the same amount of bytes but can not open in an image viewer.

I checked the permissions 4 moodle data and moodle application's folder, and its everything okay.

I'm trying to re-upload all the images used by my theme, such as the logo, because they are all broken.

Could someone tell me a way to debug this problem or sometimes a possible solution?


Thanks!!

Average of ratings: -
In reply to Fox Jah

Re: Broken file when upload

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

* switch on Debugging

* right click on a broken image and open in a new tab/window

* what error messages (if any) do you see in the new tab/window?

In reply to Howard Miller

Re: Broken file when upload

by Fox Jah -

Icon's images show this error (in new tab)

"error on line 2 at column 6: XML declaration allowed only at the start of the document"


Logo and others images upload by admin panel or user, show's a blank square with white lines when open in new tab (no error messages)



In reply to Howard Miller

Re: Broken file when upload

by Fox Jah -

I dont know why, but when i click to see de page's source code, in the first line i found a blank line...


1.

2. <!DOCTYPE html> 

3. <html dir="ltr" lang="en-us" xml:lang="en-us">

In reply to Fox Jah

Re: Broken file when upload

by Fox Jah -

I run this command

diff -y <(xxd downloadedimage.png) <(xxd originalimage.png) | colordiff
Result (The pipe "|" is the separator)

00000000: 0a89 504e 470d 0a1a 0a00 0000 0d49 4844  ..PNG..... | 00000000: 8950 4e47 0d0a 1a0a 0000 000d 4948 4452  .PNG......


So... i don't know why but when i upload an image, moodle add's/changes the first byte as we see above...

In reply to Fox Jah

Re: Broken file when upload

by Fox Jah -

Just as POC i made this simple script, where i download a "corrupted" image and save them without the first byte, so... this works \o/ angry

<?php

$binary = file_get_contents('downloaded.png',0,null,1); // 1=offset

file_put_contents('./newImage.png', $binary);

?>

In reply to Fox Jah

Re: Broken file when upload

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Check your config.php file. Has an extra character crept in before the initial <? 

...or, have you added a final ?> (don't)

Average of ratings: Useful (2)
In reply to Howard Miller

Re: Broken file when upload

by Matteo Scaramuccia -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Hello,
I second Howard's suggestion: 0A means Line Feed.

Please double check your config.php file and any third party plug-in you've recently installed: there, you should find the extra LF.

HTH,
Matteo

Average of ratings: Useful (1)
In reply to Howard Miller

Re: Broken file when upload

by Fox Jah -

@Howard Miller

@Matteo Scaramuccia

I do not believe it was something so simple, I would like to thank you immensely for your time and patience with the beginners! Thank you very much!!! Moodle ONLINE without errors !! Thank you!!