0

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/"

2
  • Where do you get the "nome_upd" from? Shouldn't it just be: $check = getimagesize($_FILES["fileToUpload"]["name"]); Commented May 15, 2017 at 16:46
  • yep, I just discovered that there are specific names to use for the values Commented May 15, 2017 at 16:59

1 Answer 1

1

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"]);
Sign up to request clarification or add additional context in comments.

1 Comment

Ok, that solved my problem, didn't know that there were specific names for that in order to work, will remember that next time, thanks :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.