Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Not a member yet? Click here to register.
Forgot Password?

Invalid Image Fix

Asked Modified Viewed 7,001 times
Y
yukisho
Y
  • Newbie, joined since
  • Contributed 6 posts on the community forums.
  • Started 1 thread in the forums
  • Started this discussions
asked
Newbie

I had the same issue like many others with this error when members would try and upload an avatar or add an image to a signature. I have managed to fix this and would like to share it.

First off let's open up includes/bbcode/img_bbcode_include.php

Find
$avdata = @getimagesize("$matches[1]$matches[3]$matches[4]");


Add below
$avdata = $matches[4]; // Fix Wanabo



Now open up includes/mimetypes_includes.php

Find the jpe,jpeg,jpg,png,gif lines and replace them with the following
   'gif'   =>   'image/gif',
   'jpeg'   =>   'image/jpeg',
   'jpg'   =>   'image/jpeg',
   'jpe'   =>   'image/jpeg',
   'png'   =>   'image/png',


This has fixed my issues and so far as I can tell has not created any other issues.
0 replies

7 posts

F
Falk
F
Falk 131
Need help?, Having trouble?
• View our Documentation for Guides, Standards and Functions
• Name and Organize your Topics and Content correctly in the corresponding Forums for best support results
• Attaching Log Files and Screenshots when reporting issues will help
• Provide with an URL to live example if one exists
• Please read the How to Report an Error post
• Please read and comply with the Code of Conduct

(¯·._.·(¯°·._.·°º*[ Project Manager ]*º°·._.·°¯)·._.·¯)
  • Super Admin, joined since
  • Contributed 6,201 posts on the community forums.
  • Started 639 threads in the forums
  • Answered 11 questions
answered
Super Admin

:G
0 replies
R
Ralph68
R
Regards,
Ralph
  • Member, joined since
  • Contributed 108 posts on the community forums.
  • Started 1 thread in the forums
answered
Member

This is the second time I've tried this fix which it does not work for me.

when I try to attach a .png to a post I get "file type not allowed."
And "Invalid image" when adding a image file to my signature.
Also can not attach .z7

My Test site
Edited by Ralph68 on 21-09-2013 17:03,
0 replies
F
Falk
F
Falk 131
Need help?, Having trouble?
• View our Documentation for Guides, Standards and Functions
• Name and Organize your Topics and Content correctly in the corresponding Forums for best support results
• Attaching Log Files and Screenshots when reporting issues will help
• Provide with an URL to live example if one exists
• Please read the How to Report an Error post
• Please read and comply with the Code of Conduct

(¯·._.·(¯°·._.·°º*[ Project Manager ]*º°·._.·°¯)·._.·¯)
  • Super Admin, joined since
  • Contributed 6,201 posts on the community forums.
  • Started 639 threads in the forums
  • Answered 11 questions
answered
Super Admin

But the above fix cover two separe things.

One is the IMG verify for BBCodes, we have a very refined function for this that needs some debuging before we can use it.

The other one is the global uploads MIME check function.
I do realize that this general check of all uploads can be abit to much for many people.
The function do parse headers if new / updated compressors adds values to the header the files will fail. How to debug this is described in the orginal post when people started to get problems.

This our refined bbcode (includes\bbcodes\img_bbcode_include.php) function that sometimes have throw a fatal error: Can't use function return value in write context in img_bbcode_include.php on line 54

This is one only woks for some people, I have not had the time to go to the bottom with why it works for some only. You can give it a go.



<?php

if (!defined("IN_FUSION")) { die("Access Denied"); }

if (!function_exists("img_bbcode_callback")) {
   function img_bbcode_callback($matches) {

   // Include locales
   if (file_exists(LOCALE.LOCALESET."bbcodes/img.php")) {
      include (LOCALE.LOCALESET."bbcodes/img.php");
   } elseif (file_exists(LOCALE."English/bbcodes/img.php")) {
      include (LOCALE."English/bbcodes/img.php");
   }

      if (substr($matches[3], -1, 1) != "/") {
         $il = "$matches[1]$matches[3]$matches[4]";

         if (function_exists('curl_init')) { // If cURL is available, use it.
            $curl = curl_init();
            curl_setopt($curl, CURLOPT_URL, $il);
            curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); // This MUST be kept as it is used to block one of the XSRF image bypassing techniques.
            curl_setopt($curl, CURLOPT_FILETIME, true);
            curl_setopt($curl, CURLOPT_NOBODY, true);
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($curl, CURLOPT_TIMEOUT, 1); // execution time allowed in seconds
            $header = curl_exec($curl);
            $headers = explode("\n", $header);
            $content_types = curl_getinfo($curl);
            $content_size = curl_getinfo($curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
            curl_close($curl);
            $content_type = $content_types["content_type"];
            $content_size = (int) $content_size;
         } else {
            if (isset(get_headers($il,2)['Content-Type'])) {         
               $chksize = get_headers($il,1)['Content-Length'];
               $chksize = (int) $chksize;
               
               if ($chksize >= 1 && $chksize != NULL && $chksize != false) {
                  $content_type = get_headers($il,2)['Content-Type'];
                  $content_size = $chksize;
                  $imageIsValid = true;
               } else {
                  $imageIsValid = false;
                  $err_msg = $locale['bb_img_error_not_valid'];
               }
            } else {
               $imageIsValid = false;
               $err_msg = $locale['bb_img_error_not_valid'];
            }
         }

         $content_type = $content_type; // This can still be faked, but as the FOLLOWLOCATION is used, they cannot fake YOUR header responses.

         if (!preg_match("/image|jpg|jpeg|gif|png/i", $content_type)) {
            $imageIsValid = false;
            $err_msg = $locale['bb_img_error_not_valid'];
         } else {
            if (preg_match("/-/i", $content_size) || $content_size <= 2) {
               $imageIsValid = false;
               $err_msg = $locale['bb_img_error_fake'];
            } else {
               $imageIsValid = true;
            }
         }

         // If image is valid
         if ($imageIsValid == true) {   
            return "<span style='display: block; max-width: 300px; max-height: 300px; overflow: auto;' class='forum-img-wrapper'><img src='".$matches[1].str_replace(array("?","&amp;","&","="), "", $matches[3]).$matches[4]."' alt='".$matches[3].$matches[4]."' style='border:0px' class='forum-img' /></span>";
         } else {
            return "<span class='invalid-image' style='text-decoration: line-through' title='".$err_msg."'>$matches[1]$matches[3]$matches[4]</span>";
         }

      // End of BBCode IMG tag patch by Euforia33
      } else {
         return "<span class='invalid-image' style='text-decoration: line-through' title='".$locale['bb_img_error_other']."'>$matches[1]$matches[3]$matches[4]</span>";
      }
   }
}

$text = preg_replace_callback("#\[img\]((http|ftp|https|ftps)://)(.*?)(\.(jpg|jpeg|gif|png|JPG|JPEG|GIF|PNG|PHP))\[/img\]#si", "img_bbcode_callback", $text);
?>
Edited by N/A on 24-09-2013 04:53,
0 replies
Y
yukisho
Y
  • Newbie, joined since
  • Contributed 6 posts on the community forums.
  • Started 1 thread in the forums
  • Started this discussions
answered
Newbie

Quote

Ralph68 wrote:

This is the second time I've tried this fix which it does not work for me.

when I try to attach a .png to a post I get "file type not allowed."
And "Invalid image" when adding a image file to my signature.
Also can not attach .z7

My Test site


Give mine a shot. I have included the edited files in this rar file.

Download
0 replies
R
Ralph68
R
Regards,
Ralph
  • Member, joined since
  • Contributed 108 posts on the community forums.
  • Started 1 thread in the forums
answered
Member

Quote

yukisho wrote:

Quote

Ralph68 wrote:

This is the second time I've tried this fix which it does not work for me.

when I try to attach a .png to a post I get "file type not allowed."
And "Invalid image" when adding a image file to my signature.
Also can not attach .z7

My Test site


Give mine a shot. I have included the edited files in this rar file.

Download



yukisho, I'm getting the following errors.

Error Message: "Attachments File Type Not Allowed". .gif files.
Error Message: "Attachments File Type Not Allowed". .z7 files.
Error Message: Same signature error, invalid image url.

Not sure if this is a problem but you have line:25 like this in your files.
         $avdata = @getimagesize("$matches[1]$matches[3]$matches[4]");         $avdata = $matches[4]; // Fix Wanabo            $avdata = $matches[4]; // Fix Wanabo


yukisho's attachment test

Merged on Sep 29 2013 at 19:12:59:
Domi, Your file fixed the signature error and I was able to upload .png. But I'm still not able to upload .z7 file and .gif with your fix.

Test Post

Merged on Sep 29 2013 at 20:25:43:
I just re-download php-fusion v7.02.07 full, 10min ago.
Created a new database and installed a fresh copy.
I did not restore my db from backup.

I got: "Attachments File Type Not Allowed". for .gif file

Everything else looks good.
.png... ok
.jpg... ok
.zip... ok
.rar... ok
.z7... ok
Signature... ok


New Test Site

Merged on Sep 29 2013 at 22:06:31:
I found something strange happening for me.

If I remove .tar from: Settings/Forum/Allowed file types:.gif,.jpg,.png,.zip,.rar,.7z

When attaching a .z7 file type will give error, "Attachments File Type Not Allowed".

But when I add .tar back to line, Settings/Forum/Allowed file types:.gif,.jpg,.png,.zip,.rar,.tar,.7z

.z7 files attach ok.
Edited by Ralph68 on 30-09-2013 04:07,
0 replies
A
Aokiji
A
Aokiji 10
  • Junior Member, joined since
  • Contributed 35 posts on the community forums.
  • Started 17 threads in the forums
answered
Junior Member

if tried this and i still get not a valid image... when trying to set signature

Merged on Oct 23 2013 at 21:53:45:
no one has a solution for me? cant even link pics in forum
Edited by Aokiji on 23-10-2013 20:53,
0 replies
P
PolarFox
P
  • Veteran Member, joined since
  • Contributed 1,633 posts on the community forums.
  • Started 29 threads in the forums
answered
Veteran Member

You just need to use old bbcodes from v7.02.06 (or prior).
0 replies

Labels

None yet

Statistics

  • Views 0 views
  • Posts 7 posts
  • Votes 0 votes
  • Topic users 5 members

5 participants

F
F
Falk 131
Need help?, Having trouble?
• View our Documentation for Guides, Standards and Functions
• Name and Organize your Topics and Content correctly in the corresponding Forums for best support results
• Attaching Log Files and Screenshots when reporting issues will help
• Provide with an URL to live example if one exists
• Please read the How to Report an Error post
• Please read and comply with the Code of Conduct

(¯·._.·(¯°·._.·°º*[ Project Manager ]*º°·._.·°¯)·._.·¯)
  • Super Admin, joined since
  • Contributed 6,201 posts on the community forums.
  • Started 639 threads in the forums
  • Answered 11 questions
R
R
Regards,
Ralph
  • Member, joined since
  • Contributed 108 posts on the community forums.
  • Started 1 thread in the forums
P
P
  • Veteran Member, joined since
  • Contributed 1,633 posts on the community forums.
  • Started 29 threads in the forums
A
A
Aokiji 10
  • Junior Member, joined since
  • Contributed 35 posts on the community forums.
  • Started 17 threads in the forums
Y
Y
  • Newbie, joined since
  • Contributed 6 posts on the community forums.
  • Started 1 thread in the forums
  • Started this discussions

Notifications

Track thread

You are not receiving notifications from this thread.

Related Questions

Not yet