duanqiang2977 2013-05-23 01:30
浏览 74

代码改进[关闭]

Okay, I'm just a little newbie in programming just doing it for a past time hobby. I am just recently making a web editor for fun and the way I was doing it (Using PHP) I was told would be a bad way. I also thought about it while I was making it, and in massive sums of data transfer it would be a bad idea to do it this way. Thing is I can't think of another way to do it and was looking for someone to help me improve it, by it I mean my save method I am using. Here my codes:

Editor:

<html>
<head>
<title>Web Editor</title>
<link href="controller.css" rel="stylesheet"/>
<script type="text/javascript" src="script/editor.js"></script>
</head>
<body>
<div class="platform">
<div class="head"><div class="file"><p>File: <div id="file">C:\hello.html</div></p></div></div>
<div class="hotbar"><img src="images/save.png" class="hotbarImage" onClick="save()" />

</div>
<div class="editor"><div contenteditable="true" style="height:100%; overflow:scroll;" id="editPad"></div></div>
</div>




</body>
</html>

JS:

function save() {
    var dir = document.getElementById("file").innerHTML;
    var data = document.getElementById("editPad").innerHTML;
    window.location = "save.php?dir="+encodeURIComponent(dir)+"&data="+encodeURIComponent(data);
}

PHP:

<?php
$dir = $_GET['dir'];
$data = $_GET['data'];
$lookFor = array("&lt;", "&gt;","<br>","<%2Fdiv>","<div>","</div>");
$replaceWith = array("<", ">", "", "", "","");
$newData = str_replace($lookFor,$replaceWith,$data);

$f = fopen(urldecode($dir),"w");
fwrite($f,urldecode($newData));
fclose($f);
?>

All of it is just a work in progress and need more done. But for right now, is there a better way for me to save the file with massive sums of data being transfer.

  • 写回答

2条回答 默认 最新

  • dsadsa123111 2013-05-23 01:34
    关注

    You shouldn't use a GET request for storing data for several reasons but the most important one being: GET requests have a limit to how long they can be.

    If you have very large content it might just be that you can't save it because your browser wont send the URL or the server wont accept it (because it's too long).

    What you can do is make a hidden form, fill the fields you need and submit it with JavaScript. Make sure to set action="post".

    评论

报告相同问题?

悬赏问题

  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?