简体   繁体   中英

Error displayed in php upload form

I have a php form that should theoretically upload image files to a specific directory, but it does not do that. This is the HTML:

<!DOCTYPE html>
<html>
<body>

<form action="upload.php" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>

</body>
</html>

And this is the php:

<?php
$cartella_caricamento = "pagamenti/";
$file_caricato = $cartella_caricamento.basename($_FILES["fileToUpload"]
["name"]);
$uploadOk=1;
$imageFileType=pathinfo($file_caricato,PATHINFO_EXTENSION);
if(isset($_POST["submit"]))
{
$check = getimagesize($_FILES["fileToUpload"]["nome_upd"]);
if($check !== false)                                                            //Check if the file is an image
{
echo "Il file è un immagine, OK".$check["mime"].".";
$uploadOk=1;
} else {
echo "Il file non è un immagine.";                  
$uploadOk=0;
}
if ($_FILES["fileToUpload"]["size"] > 2000000) {                                    //check the image size, if it is >2MB it refuses it
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
if ($uploadOk==0) {
echo "Il file non è stato caricato a causa di un errore";
} else {
if(move_uploaded_file($_FILES["file_caricato"]["nome_upd"], $file_caricato))
{
echo "Il file".basename($_FILES["fileToUpload"]["name"])."è stato caricato";
}else {
echo "C'è stato un errore nel caricamento del file.";
}
}
}

The problem is that when I run the page using XAMPP it says that in line 21

$check = getimagesize($_FILES["fileToUpload"]["nome_upd"]);

there is an undefined index (nome_tmp) and I don't know why And the image that I chose in the explorer window is not being uploaded to the directory "pagamenti/"

You appear to be using Italian wording for English language auto-filled array keys. I'm not aware if there's a local language plugin to accept this, but the standard array values can be found here .

$_FILES['userfile']['name']
The original name of the file on the client machine.

$_FILES['userfile']['type']
The mime type of the file, if the browser provided this information. An example would be "image/gif". This mime type is however not checked on the PHP side and therefore don't take its value for granted.

$_FILES['userfile']['size']
The size, in bytes, of the uploaded file.

$_FILES['userfile']['tmp_name']
The temporary filename of the file in which the uploaded file was stored on the server.

$_FILES['userfile']['error']
The error code associated with this file upload.

So from reading your code, the array value you should be using is tmp_name .

/***
 * Will use the uploaded file path
 ***/ 
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM