my code is suppose to jump to the next page after the upload was successful but i’ve got this warning.
‘
Warning: Cannot modify header information – headers already sent by (output started at C:\XAMP\xampp\htdocs\gallery\uploader3.php:25) in C:\XAMP\xampp\htdocs\gallery\uploader3.php on line 51
here is the code:
<html>
<head>
<title> Sample1 - File Upload on Directory </title>
</head>
<body>
<div align="center">
<form action="uploader3.php" method="post" enctype="multipart/form-data" >
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Create an Album (limited to 10 images): <br />
<input type="file" name="uploadedfile[]" /><br />
<input type="file" name="uploadedfile[]" /><br />
<input type="file" name="uploadedfile[]" /><br />
<input type="file" name="uploadedfile[]" /><br />
<input type="file" name="uploadedfile[]" /><br />
<input type="file" name="uploadedfile[]" /><br />
<input type="file" name="uploadedfile[]" /><br />
<input type="file" name="uploadedfile[]" /><br />
<input type="file" name="uploadedfile[]" /><br />
<input type="file" name="uploadedfile[]" /><br />
<br />
<input type="submit" value="Upload File" />
</form>
</div>
<?php
$target_path = "uploads1/";
if(!file_exists($target_path))
{
if(!mkdir($target_path))
{
die ("could not create the folder");
}
}
else
{
for($count = 0; $count < count($_FILES['uploadedfile']); $count++)
{
$target_path = $target_path . basename( $_FILES['uploadedfile']['name'][$count]);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'][$count], $target_path))
{
/*echo "The file ". basename( $_FILES['uploadedfile']['name'][$count]).
" has been uploaded";*/
}
else
{
echo "There was an error uploading the file, please try again!";
}
}
}
header('Location: index.html');
?>
</body>
</html>
how can I solve this? Thanks AHEAD! 😀
Your code flow is wrong. Your php script is being executed as soon as that page loads, not when the user submits the form
You need to move the code thats between
<?php ?>(including those tags) to uploader3.php as thats where your forms target action is set to.Alternatively you can put the script at the top of the page and check that form data has been sent, and remove the action attribute from the form tag so that it just submits back to itself or change it so it points back to itself
Example