darylfromjax Posted May 2, 2007 Share Posted May 2, 2007 (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 More sharing options...
trq Posted May 2, 2007 Share Posted May 2, 2007 Why are there forward slashes in your urls? Link to comment https://forums.phpfreaks.com/topic/49601-giving-file22httpanysitecom22-instead/#findComment-243199 Share on other sites More sharing options...
darylfromjax Posted May 2, 2007 Author Share Posted May 2, 2007 I started without the forward slashes and it did not work. Someone suggested trying it. I just did not take the slashes out before posting here. Link to comment https://forums.phpfreaks.com/topic/49601-giving-file22httpanysitecom22-instead/#findComment-243210 Share on other sites More sharing options...
trq Posted May 2, 2007 Share Posted May 2, 2007 Forward slashes mean nothing. Have you got a link to this page we can view? Link to comment https://forums.phpfreaks.com/topic/49601-giving-file22httpanysitecom22-instead/#findComment-243216 Share on other sites More sharing options...
darylfromjax Posted May 2, 2007 Author Share Posted May 2, 2007 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. Link to comment https://forums.phpfreaks.com/topic/49601-giving-file22httpanysitecom22-instead/#findComment-243224 Share on other sites More sharing options...
darylfromjax Posted May 2, 2007 Author Share Posted May 2, 2007 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> Link to comment https://forums.phpfreaks.com/topic/49601-giving-file22httpanysitecom22-instead/#findComment-243231 Share on other sites More sharing options...
darylfromjax Posted May 3, 2007 Author Share Posted May 3, 2007 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. Link to comment https://forums.phpfreaks.com/topic/49601-giving-file22httpanysitecom22-instead/#findComment-244104 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.