Hey there, I started learning PHP few days ago, and after understanding all the basics, there is tutorial about uploading files. So, I do understand that a bit, I do understand PHP part, but the part I don't understand is HTML. Here is first HTML part i have:
<html>
<body>
<form action="test.php" method="POST" enctype="multipart/form-data">
<label for="file">Filename: </label><br />
<input type="file" name="file" id="file"><br />
<input type="submit" value="submit" name="submit">
</form>
</body></html>
So, basicly what I don't understand is this attribute in label : for = "file" AND what for I have id="file" ? I basicly retyped this from w3School.
And PHP part I reedited:
<?php
$extension = array('txt');
$catch_extension = end(explode('.',$_FILES['file']['name']));
if ( ($_FILES['file']['type'] == 'text/plain') && in_array($catch_extension,$extension) ) {
if($_FILES['file']['error'] > 0) {
echo "Error: " . $_FILES['file']['error'];
} else {
if (file_exists('upload/' . $_FILES['file']['name'])) {
echo "File with that name allready exists.";
} else {
move_uploaded_file($_FILES['file']['tmp_name'],'upload/' . $_FILES['file']['name']);
echo "You have uploaded file. Good job.";
}
}
} else {
echo "Invalid type of file.";
}?>