Jump to content

URL Encoding driving me Crazy!!!


everettcomstock

Recommended Posts

Hi Everyone,
      Sorry to bother you all, but I have a problem that is just driving me nuts. I am a novice PHP programmer, and I have programmed two different sites to display an album cover. The first site is www.otteradio.com. This site shows the currently playing album cover and song name. I have a personal website (www.everettcomstock.com) that shows the same album cover and song name.
The otterradio.com site always displays the cover picture correctly, but my personal site will not show pictures if the title includes and apostrophe. I am not using a database like MySQL, and the links are all Raw URL Encoded. I am going to post a little bit of my script in hopes that it will help any of you who are interested in this problem.

I use a separate file to actually display the image and image header (image.php)
I call it from a URL embedded in am IMG tag:
<?php

$path = $_GET[path];

$image = imagecreatefromjpeg("$path\folder.jpg");

header("Content-Type: image/jpeg");

imagejpeg($image);

?>

I have a separate file where I gather current song information (getsonginfo.php) to create the link for the URL used to call image.php:
<?php

$info = file("D:\Webroot\everett\otterradio\history\songhistory.html");


$Artist = array("$info[0]", "$info[4]", "$info[8]", "$info[12]", "$info[16]",
"$info[20]", "$info[24]", "$info[28]", "$info[32]", "$info[36]");

$Song = array("$info[1]", "$info[5]", "$info[9]", "$info[13]", "$info[17]",
"$info[21]", "$info[25]", "$info[29]", "$info[33]", "$info[37]");

$Album = array("$info[2]", "$info[6]", "$info[10]", "$info[14]", "$info[18]",
"$info[22]", "$info[26]", "$info[30]", "$info[34]", "$info[38]");

$File = array("$info[3]", "$info[7]", "$info[11]", "$info[15]", "$info[19]",
"$info[23]", "$info[27]", "$info[31]", "$info[35]", "$info[39]");


$y=0;

While ($y != '10'){                   
     
$filepath = pathinfo($File[$y]);  //File Path

$dirpath = $filepath[dirname]; //Convert to Directory Path

$rawencode = rawurlencode($dirpath); //Raw Encode the path to HTTP URL

$Path[$y] = $rawencode; //Store Path Variable

$y++;

}

$x=0;

While ($x != '10'){

if ($x=="0"){

$imagepath = "<img class='npcover' src='http://otterradio.com/songinfo/image.php?path=$Path[$x]'>";                    
      }

else {

$imagepath = "<img class='cover' src='http://otterradio.com/songinfo/image.php?path=$Path[$x]'>";
}

$Image[$x] = $imagepath;

$x++;

}

?>

And finally, I include the getsonginfo.php file on both pages and place the $Image[0] variable where I want the cover art to be displayed. Again, for some reason, it works great at otterradio.com, but at everettcomstock.com, the art does not display when the artist name or song title has an apostrophe in it.

  Sorry for posting so much code. Thanks for all of the help. And, if you have any suggestions outside of my question, I would love to hear them.

Everett
Link to comment
Share on other sites

If it works in some browsers and not in other than your issue is with your html not php. PHP is well and truely finished before anything is sent to the browser.

View your html source for errors. Run your page through the w3c validator. This should find your issues.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.