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
https://forums.phpfreaks.com/topic/32156-url-encoding-driving-me-crazy/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.