problem in uploading one image in two directories.
Posted: Mon Sep 29, 2008 5:12 am
Hope all is well here.
first of all sorry, if i posted this in wrong category.
And thanks in advance,
Now the problem is this.
I have two directories on my server( localhost)
named
images/ and
thumbs/
> one upload form field with a submit button.
I want to upload the image in both directories as i click on submit button/.
But as i do this, it gets upload to only images folder, no file reaches to thumbs folder.
I need the same name for both folders.
please help me to upload this in both directories I will be very thank ful to you all.
the code i wrote is:
<?php
if(isset($_POST['BtnUpload']))
{
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/bmp"))
&& ($_FILES["file"]["size"] < 500000))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
if (file_exists("images/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
try
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"images/" . $_FILES["file"]["name"]);
move_uploaded_file($_FILES["file"]["tmp_name"],
"thumbs/" . $_FILES["file"]["name"]);
}
catch(Exception $e)
{
echo 'Message: ' .$e->getMessage();
}
try
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"thumbs/" . $_FILES["file"]["name"]);
echo 'no Error on thumbs updation: '."thumbs/" .$_FILES["file"]["name"];
}
catch(Exception $e)
{
echo 'Message: ' .$e->getMessage();
}
echo "Stored in: " . "images/" . $_FILES["file"]["name"];
$doc = new DOMDocument;
$doc->load("gallery.xml");
$doc->formatoutput = true;
$simpleviewergallery = $doc->getElementsByTagName('simpleviewergallery')->item(0);
$image = $doc->createElement('image');
$image = $simpleviewergallery->appendChild($image);
$filename = $doc->createElement('filename');
$filename = $image->appendChild($filename);
$imageurl = $doc->createTextNode($_FILES["file"]["name"]);
$imageurl = $filename->appendChild($imageurl);
$caption = $doc->createElement('caption');
$caption = $image->appendChild($caption);
$captionvalue = $doc->createTextNode($_FILES["file"]["name"]);
$captionvalue = $caption->appendChild($captionvalue);
$test = $doc->save("gallery.xml");
print '<div style=\"color:green; font-size:15pt;\">Image Uploaded successfully !</div>';
}
}
}
else
{
echo "Invalid file";
}
}
?>
actually as it gets upload it will also write in xml file and xml file send data to flash these two working fine but my real problem is uploading this to both directories
images/
thumbs/
please help...
first of all sorry, if i posted this in wrong category.
And thanks in advance,
Now the problem is this.
I have two directories on my server( localhost)
named
images/ and
thumbs/
> one upload form field with a submit button.
I want to upload the image in both directories as i click on submit button/.
But as i do this, it gets upload to only images folder, no file reaches to thumbs folder.
I need the same name for both folders.
please help me to upload this in both directories I will be very thank ful to you all.
the code i wrote is:
<?php
if(isset($_POST['BtnUpload']))
{
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/bmp"))
&& ($_FILES["file"]["size"] < 500000))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
if (file_exists("images/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
try
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"images/" . $_FILES["file"]["name"]);
move_uploaded_file($_FILES["file"]["tmp_name"],
"thumbs/" . $_FILES["file"]["name"]);
}
catch(Exception $e)
{
echo 'Message: ' .$e->getMessage();
}
try
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"thumbs/" . $_FILES["file"]["name"]);
echo 'no Error on thumbs updation: '."thumbs/" .$_FILES["file"]["name"];
}
catch(Exception $e)
{
echo 'Message: ' .$e->getMessage();
}
echo "Stored in: " . "images/" . $_FILES["file"]["name"];
$doc = new DOMDocument;
$doc->load("gallery.xml");
$doc->formatoutput = true;
$simpleviewergallery = $doc->getElementsByTagName('simpleviewergallery')->item(0);
$image = $doc->createElement('image');
$image = $simpleviewergallery->appendChild($image);
$filename = $doc->createElement('filename');
$filename = $image->appendChild($filename);
$imageurl = $doc->createTextNode($_FILES["file"]["name"]);
$imageurl = $filename->appendChild($imageurl);
$caption = $doc->createElement('caption');
$caption = $image->appendChild($caption);
$captionvalue = $doc->createTextNode($_FILES["file"]["name"]);
$captionvalue = $caption->appendChild($captionvalue);
$test = $doc->save("gallery.xml");
print '<div style=\"color:green; font-size:15pt;\">Image Uploaded successfully !</div>';
}
}
}
else
{
echo "Invalid file";
}
}
?>
actually as it gets upload it will also write in xml file and xml file send data to flash these two working fine but my real problem is uploading this to both directories
images/
thumbs/
please help...