$target_dir = "attachs/";
echo "t dir= ".$target_dir;
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "<center><h1><br>File is an image - " . $check["mime"] . ".</h1></center>";
$uploadOk = 1;
} else {
echo "<center><h1><br>File is not an image.</h1></center>";
$uploadOk = 0;
}
}
// Check if file already exists
if (file_exists($target_file)) {
echo "<br><center><h1>file already exists.</h1></center>";
// $uploadOk = 0;
}
// Check file size
//if ($_FILES["fileToUpload"]["size"] > 500000) {
// echo "Sorry, your file is too large.";
// $uploadOk = 0;
//}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
echo "<br><center><h1>Sorry, only JPG, JPEG, PNG & GIF files are allowed.</h1></center>";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "<br><center><h1>Sorry, your file was not uploaded.</h1></center>";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "<br><br><br><center><h1>The file:</h1></center>";
echo "<center> <h1 style='color:Red;'>". basename( $_FILES["fileToUpload"]["name"]). "</h1></center>";
echo "<center><h1>has been uploaded</h1></center>";
//------------------------------------------------------
rename($target_file, "attachs/f".$number.".jpg");
//------------ file write --------------------
$myfile = fopen("last_file.txt", "w") or die("Unable to open file!");
fwrite($myfile, $number);
fclose($myfile);