2 $target_dir = "esercizi/";
3 $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
5 $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
6 // Check if image file is a actual image or fake image
7 /*if(isset($_POST["submit"])) {
8 $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
10 echo "File is an image - " . $check["mime"] . ".";
13 echo "File is not an image.";
17 // Check if file already exists
18 if (file_exists($target_file)) {
19 echo "Sorry, file already exists.";
23 if ($_FILES["fileToUpload"]["size"] > 500000) {
24 echo "Sorry, your file is too large.";
27 // Allow certain file formats
28 /*if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
29 && $imageFileType != "gif" ) {
30 echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
33 // Check if $uploadOk is set to 0 by an error
35 echo "Sorry, your file was not uploaded.";
36 // if everything is ok, try to upload file
38 if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
39 echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
41 echo "Sorry, there was an error uploading your file.";
50 <form action="main.php">
51 <input type="submit" value="indietro" name="submit">