• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

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

EQnoble

Well-known member
#1
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.)
 

EQnoble

Well-known member
#2
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 />";
      }
 

Laric

Active member
#3
PHP:
          if ($_FILES["file"]["type"] == "image/png")
      {
       echo '<img src="/data/media/' . trim($_FILES["file"]["name"]) . '"><br />';
      }
Think that would work just fine.
 

EQnoble

Well-known member
#5
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.
 

Laric

Active member
#9
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?
 

Laric

Active member
#10
PHP:
          if ($_FILES["file"]["type"] == "image/png")
      {
       echo '<img src="/data/media/' . trim($_FILES["file"]["name"]) . '" /><br />';
      }
Forgot to close the img tag
 

EQnoble

Well-known member
#11
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
 

EQnoble

Well-known member
#12
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 :)
 

EQnoble

Well-known member
#13
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.
 

Shadab

Well-known member
#15
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);
 

EQnoble

Well-known member
#16
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.