1. 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.

Discussion in 'XenForo Development Discussions' started by EQnoble, Mar 2, 2011.

  1. EQnoble

    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.)
     
  2. EQnoble

    EQnoble Well-Known Member

    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 />";
          } 
     
  3. Laric

    Laric Active Member

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

    Laric Active Member

    The browsers that showed the original code as an image is not doing it quite right as you never closed your src=" uri.
     
    EQnoble likes this.
  5. EQnoble

    EQnoble Well-Known Member

    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.
     
  6. EQnoble

    EQnoble Well-Known Member


    how do I correctly close it in this instance?...everything I try spits back errors.
     
  7. Laric

    Laric Active Member

    did you try my code snippet?
     
    EQnoble likes this.
  8. EQnoble

    EQnoble Well-Known Member

    i did...it seems as though it is not working...it ends up displaying the page the same way.
     
  9. Laric

    Laric Active Member

    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?
     
    EQnoble likes this.
  10. Laric

    Laric Active Member

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

    EQnoble Well-Known Member

    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
     
  12. EQnoble

    EQnoble Well-Known Member

    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 :)
     
  13. EQnoble

    EQnoble Well-Known Member

    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.
     
  14. EQnoble

    EQnoble Well-Known Member

    Again I would like to thank you for pointing out my error Laric...it is MUCH appreciated.
     
  15. Shadab

    Shadab Well-Known Member

    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);
     
    Kier and EQnoble like this.
  16. EQnoble

    EQnoble Well-Known Member

    hmmm...
    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.
     
  17. Shadab

    Shadab Well-Known Member

    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
     
    EQnoble likes this.
  18. EQnoble

    EQnoble Well-Known Member

    Thank you for this Shedab (yet again)...yay I have homework...<opens php.net>
     
    Shadab likes this.

Share This Page