Programming - PHP - File upload
Quick code snippet in PHP to upload imagesandto a
site:
<html>
<body><form action="upload.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Submit"
/>
</form></body>
</html>
This PHP file looks like:
<?php
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000))
and {
and if ($_FILES["file"]["error"] > 0)
and {
and echo "Return Code: " .
$_FILES["file"]["error"] . "<br />";
and }
and else
and {
and echo "Upload: " . $_FILES["file"]["name"] .
"<br />";
and echo "Type: " . $_FILES["file"]["type"] .
"<br />";
and echo "Size: " . ($_FILES["file"]["size"] /
1024) . " Kb<br />";
and echo "Temp file: " .
$_FILES["file"]["tmp_name"] . "<br />";and
if (file_exists("upload/" . $_FILES["file"]["name"]))
and {
and echo $_FILES["file"]["name"] . "
already exists. ";
and }
and else
and {
and
move_uploaded_file($_FILES["file"]["tmp_name"],
and "upload/" .
$_FILES["file"]["name"]);
and echo "Stored in: " . "upload/" .
$_FILES["file"]["name"];
and }
and }
and }
else
and {
and echo "Invalid file";
and }
?>