Jump to content

<a href=/"http://anysite.com"/> giving file://%22http://anysite.com//%22 instead


darylfromjax

Recommended Posts

(I am using php 4.4.1)

 

I am using code from PowerfulSquid that allows my user to update text on the page by updating txt files that are included into my page.  But whenever a <a HREF=/"http://anysite.com"/> or <a HREF=/"mailto:[email protected]"/> is used, it displays the wrong address.  Such as "file://%22http://anysite.com//%22".

 

 

Php: (text file updated is listed after the php code)[/b]

I got this code from http://www.phpfreaks.com/quickcode/Reading-in-Files-from-a-Directory-and-Editing-Them/68.php.

<?

 

$file_dir="other"; // DIRECTORY YOU WISH TO VIEW AND EDIT THE FILES IN

 

$f_types=array("php","html","txt"); // FILE TYPES YOU WISH TO BE ABLE TO EDIT

 

if(!isset($action))

{

$dir=opendir($file_dir);

while ($file=readdir($dir))

{

if ($file != "." && $file != "..")

{

echo "<a href=".$file_dir."/".$file." target=_blank>".$file."</a>";

$extension=substr($file,-3);

$extension2=substr($file,-4);

for($x=0;$x < count($f_types); $x++)

{

if($extension == $f_types[$x] || $extension2 == $f_types[$x])

{

echo "  |  <a href=".$_SERVER['PHP_SELF']."?action=edit&file=".$file_dir."/".$file.">EDIT</a>";

}

}

echo "<br>";

}

}

}

else if($action == "edit")

{

$fp=fopen($file, "a+");

echo "<form action=".$_SERVER['PHP_SELF']."?action=update&file=".$file." method=post><textarea rows=20 cols=60 name=newcontent>";

while (!feof($fp))

{

$data=fgets($fp, 900);

echo $data;

}

echo "</textarea><br><input type=submit value=Update></form>";

fclose($fp);

 

}

else if($action == "update")

{

$fp=fopen($file, "w");

$new_content=$_POST['newcontent'];

fwrite($fp,$new_content);

fclose($fp);

echo "Updated successfully.<br><br><a href=".$_SERVER['PHP_SELF'].">Return</a>";

 

}

?>

 

End of php code.

 

Text file that is updated:

 

<p align="center"><a href=/"http://www.jaxyachtsales.com"/><img src="/images/jys98x110.jpg" alt="Link to Jacksonville Yacht Sales" width="98" height="110" border="0"></a></p>

 

Thanks in advance,

Daryl

 

Link to comment
https://forums.phpfreaks.com/topic/49601-giving-file22httpanysitecom22-instead/
Share on other sites

I just created a sample at http://offshorerodeo.com/sample/ and with the admin at http://offshorerodeo.com/sample/frontpage.php.

It seems like after I use the update, the links get messed up.

 

On my actual site, I have the directory protected by htaccess.  This sample is not protected.

frontpage.php:

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<title>front page updates</title>

<style type="text/css">

<!--

.style1 {font-size: small}

-->

</style>

</head>

 

<body>

<h1>Front Page Update Page</h1>

<p><br>

  <a href="#frontpage">Click to see frontpage layout and field names.</a><br>

  or<br>

  Click EDIT below to update text file containing text for that section of the

  page.<br>

  <span class="style1"> <a href="../markup.htm" target="_blank">(Click on this line to display

  the "mark up" cheat sheet

  in a new window.)</a></span> </p>

<p>

<?

 

$file_dir="other"; // DIRECTORY YOU WISH TO VIEW AND EDIT THE FILES IN

$file_dir="/home/offshore/public_html/sample/front";

$file_http="http://offshorerodeo.com/sample/front/";

 

//$f_types=array("php","html","txt"); // FILE TYPES YOU WISH TO BE ABLE TO EDIT

$f_types=array("txt"); // FILE TYPES YOU WISH TO BE ABLE TO EDIT

 

if(!isset($action))

{

$dir=opendir($file_dir);

while ($file=readdir($dir))

{

if ($file != "." && $file != "..")

{

//echo "<a href=".$file_dir."/".$file." target=_blank>".$file."</a>";

echo "<a href=".$file_http."/".$file." target=_blank>".$file."</a>";

$extension=substr($file,-3);

$extension2=substr($file,-4);

for($x=0;$x < count($f_types); $x++)

{

if($extension == $f_types[$x] || $extension2 == $f_types[$x])

{

echo "  |  <a href=".$_SERVER['PHP_SELF']."?action=edit&file=".$file_dir."/".$file.">EDIT</a>";

}

}

echo "<br>";

}

}

}

else if($action == "edit")

{

$fp=fopen($file, "a+");

echo "<form action=".$_SERVER['PHP_SELF']."?action=update&file=".$file." method=post><textarea rows=20 cols=60 name=newcontent>";

while (!feof($fp))

{

$data=fgets($fp, 900);

echo $data;

}

echo "</textarea><br><input type=submit value=Update></form>";

fclose($fp);

 

}

else if($action == "update")

{

$fp=fopen($file, "w");

$new_content=$_POST['newcontent'];

fwrite($fp,$new_content);

fclose($fp);

echo "Updated successfully.<br><br><a href=".$_SERVER['PHP_SELF'].">Return</a>";

 

}

?>

</p>

<a id="#frontpage" name="#frontpage"><h2>Image of Front Page</h2></a>

<p>

<input name="imageField" type="image" src="../images/frontpage.jpg" alt="Front page update map" align="middle" width="537" height="660" border="0">

</p>

 

</body>

</html>

 

 

index.htm:

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">

<html>

<!-- DW6 -->

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<title>First Coast Offshore Rodeo</title>

</head>

<body>

<style type="text/css">

<!--

.style4 {color: #FF9900}

-->

</style>

 

<table width="100%">

<tr>

<td>

          <h1 align="center" class="style4"> Welcome to the First Coast Offshore Rodeo </h1>

<?php

include 'front/main.txt';

include 'front/body.txt';

include 'front/footer.txt';

?>

          <p align="center"> </p>

          <p align="center">  </p>

          <p align="center">  </p>

          <p> </p>

      </td>

</tr>

</table>

 

</body>

</html>

 

 

I solved my problem in one way.  But, I know there is a better way.

 

I took the double quotes out of < a href=aol.com> and <a href = mailto:[email protected] > and <img src=/images/pic.jpg>.

The quotes were causing the problem.

 

If anyone has a better way,please let me know.

 

 

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.