mattyod
05-03-2006, 04:45 PM
Hi guys,
I've been fiddling with this so long now that my brain has turned to mush. I'm sure it's something daft or simple that I've missed but maybe you guys can find it for me :)
It's a small function that tries to upload a file to folder and then either re-directs to a "Thank you" page, or a "Error - file already exists" page.
The first attempt went a bit like this...
<?php
$organisation = $_POST['organisation'];
$target_path = "uploads/" .$organisation. "/";
mkdir ($target_path);
$target_path=$target_path. basename ( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))
{
header("location:thankyou.html");
}
else
{
header("location:errorimg.html");
}
?>
and would throw out the following error...
Warning: Cannot modify header information - headers already sent by (output started at /home6/summeruni/webs/www.summerunilondon.org/htdocs/partners/uploader.php:6) in /home6/summeruni/webs/www.summerunilondon.org/htdocs/partners/uploader.php on line 12
Which seemed to be saying that the headers where started on the mkdir line.
So I addapted it to...
<?php
$organisation = $_POST['organisation'];
$target_path = "uploads/" .$organisation. "/";
if (!is_dir($target_path))
{
mkdir ($target_path);
}
$target_path=$target_path. basename ( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))
{
header("location:thankyou.html");
}
else
{
header("location:errorimg.html");
}
?>
to check directory existance first but now I ALWAYS go to the "thank you" page, irrespective of whether the file is already existing or not.
Any ideas?
Thanks in advance :)
I've been fiddling with this so long now that my brain has turned to mush. I'm sure it's something daft or simple that I've missed but maybe you guys can find it for me :)
It's a small function that tries to upload a file to folder and then either re-directs to a "Thank you" page, or a "Error - file already exists" page.
The first attempt went a bit like this...
<?php
$organisation = $_POST['organisation'];
$target_path = "uploads/" .$organisation. "/";
mkdir ($target_path);
$target_path=$target_path. basename ( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))
{
header("location:thankyou.html");
}
else
{
header("location:errorimg.html");
}
?>
and would throw out the following error...
Warning: Cannot modify header information - headers already sent by (output started at /home6/summeruni/webs/www.summerunilondon.org/htdocs/partners/uploader.php:6) in /home6/summeruni/webs/www.summerunilondon.org/htdocs/partners/uploader.php on line 12
Which seemed to be saying that the headers where started on the mkdir line.
So I addapted it to...
<?php
$organisation = $_POST['organisation'];
$target_path = "uploads/" .$organisation. "/";
if (!is_dir($target_path))
{
mkdir ($target_path);
}
$target_path=$target_path. basename ( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))
{
header("location:thankyou.html");
}
else
{
header("location:errorimg.html");
}
?>
to check directory existance first but now I ALWAYS go to the "thank you" page, irrespective of whether the file is already existing or not.
Any ideas?
Thanks in advance :)