I have a page with the following structure:
1. Text
2. Form with SUBMIT button that allows users to upload files
3. PHP code to handle the files
I'd like to complete 2 (wait for user to hit SUBMIT) before going to 3. I'd also like to keep the activity on the same page... right now if a user hits SUBMIT he/she is redirected to the upload.php script.
What's the simplest way to accomplish this, given that I'm new to PHP? Thank you for your time.
Code below:
HTML (I'd like to keep everything on this page):
<html>
<body>
<form action="upload_file.php" method="post" enctype="multipart/form-data">
<br />
<label for="file">Upload Files:</label>
<br />
<br />
<input type="file" name="file1" id="file" />
<input type="file" name="file2" id="file" />
<input type="file" name="file3" id="file" />
<br />
<br />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
<?php
//$result = $storageClient->putBlob('testcontainer', 'example.txt', 'C:/example.txt');
// I'll be uploading each of the three uploaded files here
// Syntax: putBlob (ContainerName, NameInStorage, FileLocation)
?>
Script:
<?php
error_reporting(E_ALL);
for ($i=1; $i<4; $i++)
{
$file = "file" . $i;
if (($_FILES[$file]["size"] < 20000))
{
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 />";
$moved = move_uploaded_file($_FILES[$file]["tmp_name"], "C:/inetpub/wwwroot/PHP_Ramp/upload/" . $_FILES[$file]["name"]);
if ($moved) {
echo "Move: Success <br/>";
}
else {
echo "Move Failed <br/>";
}
echo "Stored in: " . "C:/inetpub/wwwroot/PHP_Ramp/upload/" . $_FILES[$file]["name"];
}
}
else
{
echo "Invalid file";
}
}
?>