tomjolly
03-03-2007, 09:48 PM
hi,
im writing a script that takes images uploaded on a form and saves them to a directory defined by a drop down box named gallery, the script then opens an existing xml file in the specified directory and edits it, removing the closing tag, adding information to the end, then adding the closing tag.
the problem im having is with the deleteline function written by blm126, the script works fine when the gallery location is defined, but when it uses the $gallery variable from the dropdown box it wont delete the last line of the xml file
problem line:
$handle = fopen('images/'.$gallery.'/images.xml','w');
any help would be much appreciated
thanks
full code:
if(isset( $Submit ))
{
$gallery = $_POST["gallery"];
$file = 'images/'.$gallery.'/images.xml';
$width = $_POST["width"];
$title = $_POST["title"];
$caption = $_POST["caption"];
//If the Submitbutton was pressed do:
copy ($_FILES['imagefile']['tmp_name'], "images/".$gallery.'/'.$_FILES['imagefile']['name'])
or die ("Could not copy");
echo "<br>";
echo "Name: ".$_FILES['imagefile']['name']."<br>";
echo "Size: ".$_FILES['imagefile']['size']."<br>";
echo "Upload Complete....<br>";
echo "edited images/".$gallery."/images.xml<br>";
echo "click <a href='index.html'>here</a> to goto the portfolio<br>";
function deleteline($del, $filename){
$file = file($filename);
ob_start();
for($i=0;$i < count($file);$i++){
if(strpos($file[$i],$del) === FALSE){
echo $file[$i];
}
}
$write = ob_get_contents();
ob_end_clean();
$handle = fopen('images/'.$gallery.'/images.xml','w');
fwrite($handle,$write);
fclose($handle);
}
//Pass in the search term, then the filename
deleteline('</images>','images/'.$gallery.'/images.xml');
$fh = fopen($file, 'a') or die("can't open file");
$stringData = "<pic>\n";
fwrite($fh, $stringData);
$stringData = "<image>images/".$gallery.'/'.$_FILES['imagefile']['name']."</image>\n";
fwrite($fh, $stringData);
$stringData = "<imagetitle>$title</imagetitle>\n";
fwrite($fh, $stringData);
$stringData = "<caption>$caption</caption>\n";
fwrite($fh, $stringData);
$stringData = "<width>$width</width>\n";
fwrite($fh, $stringData);
$stringData = "</pic>\n";
fwrite($fh, $stringData);
$stringData = "</images>\n";
fwrite($fh, $stringData);
fclose($fh);
}
?>
im writing a script that takes images uploaded on a form and saves them to a directory defined by a drop down box named gallery, the script then opens an existing xml file in the specified directory and edits it, removing the closing tag, adding information to the end, then adding the closing tag.
the problem im having is with the deleteline function written by blm126, the script works fine when the gallery location is defined, but when it uses the $gallery variable from the dropdown box it wont delete the last line of the xml file
problem line:
$handle = fopen('images/'.$gallery.'/images.xml','w');
any help would be much appreciated
thanks
full code:
if(isset( $Submit ))
{
$gallery = $_POST["gallery"];
$file = 'images/'.$gallery.'/images.xml';
$width = $_POST["width"];
$title = $_POST["title"];
$caption = $_POST["caption"];
//If the Submitbutton was pressed do:
copy ($_FILES['imagefile']['tmp_name'], "images/".$gallery.'/'.$_FILES['imagefile']['name'])
or die ("Could not copy");
echo "<br>";
echo "Name: ".$_FILES['imagefile']['name']."<br>";
echo "Size: ".$_FILES['imagefile']['size']."<br>";
echo "Upload Complete....<br>";
echo "edited images/".$gallery."/images.xml<br>";
echo "click <a href='index.html'>here</a> to goto the portfolio<br>";
function deleteline($del, $filename){
$file = file($filename);
ob_start();
for($i=0;$i < count($file);$i++){
if(strpos($file[$i],$del) === FALSE){
echo $file[$i];
}
}
$write = ob_get_contents();
ob_end_clean();
$handle = fopen('images/'.$gallery.'/images.xml','w');
fwrite($handle,$write);
fclose($handle);
}
//Pass in the search term, then the filename
deleteline('</images>','images/'.$gallery.'/images.xml');
$fh = fopen($file, 'a') or die("can't open file");
$stringData = "<pic>\n";
fwrite($fh, $stringData);
$stringData = "<image>images/".$gallery.'/'.$_FILES['imagefile']['name']."</image>\n";
fwrite($fh, $stringData);
$stringData = "<imagetitle>$title</imagetitle>\n";
fwrite($fh, $stringData);
$stringData = "<caption>$caption</caption>\n";
fwrite($fh, $stringData);
$stringData = "<width>$width</width>\n";
fwrite($fh, $stringData);
$stringData = "</pic>\n";
fwrite($fh, $stringData);
$stringData = "</images>\n";
fwrite($fh, $stringData);
fclose($fh);
}
?>