Joop wrote:
> Well, just like I said: "It repeats itself". The general idea is to
> make a drag and drop script, to drag and drop files and maps on one
> and eachother. Releasing the mousebutton submits a form and the php
> script is set off with two arrays: $source and $taget, looking
> something like:
>
> $source["dir"] = "..";
> $source["file"] = "file1.html";
> $target["dir"] = "../map1";
> $target["file"] = "file3.html";
>
> the idea is that (in this case) the file ../file1.html is placed in
> the map ../map1 and in the config file appears after file3.html.
>
> The function works perfectly right now, and echos $new_target quite
> nicely. But when I uncomment the part that fopens, fwrites and fcloses
> it to config.map the config file looks something like this:
>
> index:file3.html;
> file1.html:1;
> file1.html:1;
> file1.html:1;
> file1.html:1;
> file3.html:user1;
> file1.html:1;
> file1.html:user1;
>
> Don't know exactly how many times, but I am trying to make it look
> like this:
>
> index:file3.html;
> file3.html:user1;
> file1.html:user1;
>
> And I don't know about the limboserver-thingy... It's probably a very
> good suggestion, but I just wanted to make my own...
> Thanks in advance...
>
How did your file start out in the first place?
A couple of things. You shouldn't use "\r\n" for our line end. Just
use "\n" - it's more portable.
And don't explode() the input. Since you want it in an array anyway,
just use file(). Must simpler and faster. Then you can either write
each array element out, or use implode("\n", $contents) then write once.
The former is slower, but takes less memory (which may be important if
it's a large file).
Also be sure to flock() your config file from before you read it until
after you write it. Otherwise you can run into major problems should
two people be trying to do something at the same time.
Now, your problem with the duplicate entries can be traced to this:
foreach($contents as $content) {
$cont = explode(":",$content);
if($cont[0] == $after) {
array_push($new_target, $content);
array_push($new_target, $file.":".$source["permissions"]);
} else {
array_push($new_target, $content);
}
} }
You are pushing the new target into the array when you test against each
element of the array. I think you only want to do it once, depending on
if the element exists already or not.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================