Php update broke something....any ideas how I can fix it.

EQnoble

Well-known member
I am asking anyone that has a solid backround in php and has a minute to take a look at a simple php script I made that stopped working when I updated php.

If you think you can help (it is literally one line) please post and I will pm you what you needs a lookin.

(also a weird side note...it works in firefox 3 but when I display it in ff4 the part in question doesn't show.)
 
This is the line that no long functions correctly...it doesn't break the page...it just wont display any more...

all my attempts to fix it yield at best the correct address for the image but for some reason includes a %20 at the end of the string.
PHP:
          if ($_FILES["file"]["type"] == "image/png")
      {
       echo "<img src=\"/data/media/" . $_FILES["file"]["name"] . "><br />";
      }
 
PHP:
          if ($_FILES["file"]["type"] == "image/png")
      {
       echo '<img src="/data/media/' . trim($_FILES["file"]["name"]) . '"><br />';
      }

Think that would work just fine.
 
The browsers that showed the original code as an image is not doing it quite right as you never closed your src=" uri.
 
Thanks for the response... I tried that just now...

The same issue happens , it won't display the image and when I add that snip back into the code the rest of the script after it doesn't display.
 
i did...it seems as though it is not working...it ends up displaying the page the same way.
 
have you had a look at the page source and see what it spits out?

Have your $_files array changed by any chance?

Also what version of php did you go from and to?
 
PHP:
          if ($_FILES["file"]["type"] == "image/png")
      {
       echo '<img src="/data/media/' . trim($_FILES["file"]["name"]) . '" /><br />';
      }

Forgot to close the img tag
 
well that's the thing nothing changed and the page still works under firefox 3.8

as it is whether I use your snip or mine in the php, it does the same thing...in firefox 4 it dies not display the image that got uploaded and when the line is included the rest of the php doesn't show up.

I am on the current built 5.2.xx
 
You my friend...deserve a cookie.... it now works again!

I think it was as simple as closing the image tag...but I'm not sure...I'm going to play with it right now and see what exactly is different as I just made compound changes.

THANK YOU SO FRIGGIN MUCH ...I was about to have a freakout session in a second :-)
 
PHP:
 if ($_FILES["file"]["type"] == "image/png")
      {
       echo '<img src="/data/media/' . $_FILES["file"]["name"] . '" /><br />';
      }
I ended up just needing to close the tag apparently...maybe firefox 3.8 ignores the error or something. I can't think of why it would work on one version of firefox and not the other besides that. Maybe something with php updates fixing insecurities and instead of breaking whole pages ignoring that? I have no clue. LOL

Point is it works now and I realize I should be more careful when it comes to simple things like this as they end up kicking me in the rear later.
 
You can use printf or sprintf if you need to build strings like that.
It's much easier to read.

PHP:
printf('<img src="/data/media/%s" /><br />', $fileName);

# or

echo sprintf('<img src="/data/media/%s" /><br />', $fileName);
 
hmmm...
You can use printf or sprintf if you need to build strings like that.
It's much easier to read.

PHP:
printf('<img src="/data/media/%s" /><br />', $fileName);

# or

echo sprintf('<img src="/data/media/%s" /><br />', $fileName);
so in my example I could use this for the same output as this below


echo
'<img src="/data/media/' . $_FILES["file"]["name"] . '" /><br />';



I am going to have to go back to the ole php manual for this im sure but...I am not understanding how that string outputs the same...Is there a simple explanation you can offer as to what that string is doing..i am a little bit lost on this one says the grasshopper.
 
In my example above, the %s thingy will be replaced by (string) contents of $fileName variable. So this way you get to embed a variable's value without messing up with nested single and double quotes.

Replace $fileName with $_FILES["file"]["name"] for your example to work.

Reference:
http://php.net/manual/en/function.sprintf.php
 
Top Bottom