# Transferring large amounts of data in web editor

I am making a web editor for fun and I was told that the way I was doing it (using PHP) 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. I can't think of another way to do it and was looking for someone to help me improve it, by that I mean my save method I am using.

Editor:

<html>

<title>Web Editor</title>
<script type="text/javascript" src="script/editor.js"></script>

<body>
<div class="platform">
<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>
</div>
</body>

</html>


JS:

function save() {
var dir = document.getElementById("file").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 I need more done. But for right now, is there a better way for me to save the file with massive sums of data being transferred?

• How much data do you expect per transfer? – Quentin Pradet May 23 '13 at 6:27
• Up to a MB. That should probably be the largest amount. – Matthew May 23 '13 at 20:37

• As for your save code, GET requests should not do anything on the server. It should only do what it was called to do, and that is to get data. I suggest you do a POST or PUT instead by using a form, or via AJAX.
• You need a more robust approach in stripping HTML from the data than doing it manually. PHP has some built-in functions to do that for you, like strip_tags. There could be better solutions that I'm not aware of as well.