I have been trying to find a way to upload an image. Well I can upload an image, but I can't get it to do the following.
Firstly I want it to be restricted to only PNG images then I want it to be renamed to pic.png lastly it will be replacing another file called pic.png in the directory above the uploader script.
I've tried many different scripts all over the internet but couldn't find one that would work. Here is my current code for the uploader.
<?php
$allowedExts = array("png");
$extension = end(explode(".", $_FILES["file"]["name"]));
if ((($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] < 2000000)
&& in_array($extension, $allowedExts)) {
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"] / 2000) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";\
if (file_exists("upload/" . $_FILES["file"]["name"])) {
echo $_FILES["file"]["name"] . " already exists. ";
} else {
move_uploaded_file($_FILES["file"]["tmp_name"],
"../" . $_FILES["file"]["name"]);
echo "Stored in: " . "../" . $_FILES["file"]["name"];
}
}
} else {
echo "Invalid file";
}
?>
Thanks heaps internet!