Uploading images PHP
Web Technologies
Web Development
2 years ago
5
Star Rating
1
Rating
_x000D_
_x000D_
I am having problems with the code, the goal is to provide site users with the opportunity to upload images, but the code is incorrect at a certain point:
500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
echo ("ciao");
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}
echo ($uploadOk);
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
} else {
--------------------------------------------------------------------
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { // HERE THE CODE RETURN FALSE
------------------------------------------------------------------
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
$query3 = "INSERT INTO immagini (idProprietario,nomeFile,anno,luogo,idRegione,nazione,didascalia,
politica,lavoro,tempoLibero,vacanze,motorizzazione,affettivita,amicizia,
mode,costumi,famiglia,scuola,musica,matrimonio,riti,idTipologiaImmagine,idArray) VALUES ($idProprietario,'$nomeFile',
$anno,'$luogo',$idRegione,'$nazione','$didascalia','$politica','$lavoro','$tempoLibero','$vacanze',
'$motorizzazione','$affettivita','$amicizia','$mode','$costumi','$famiglia',
'$scuola','$musica','$matrimonio','$riti',$idTipologiaImmagine,$idArray)";
$finish = mysqli_query($db,$query3);
echo ("ciao");
if (!$finish) {
echo ("Errore nell'inserimento");
echo ($query3);
}
else
{
echo "Inserito";
$confirm = "Inserimento";
$query4 = "INSERT INTO modificheUtenti (id,idArray,tipoModifica) VALUES ($idProprietario,$idArray, '$confirm')";
$conf = mysqli_query($db,$query4);
if($conf){
echo"SI";}else{echo $query4;}
}
}
}
?>
The problem is that in the highlighted line of code the program returns false and reports two problems:
PHP Warning: move_uploaded_file(/Database/ARCHIVIOIMAGO/back.png): failed to open stream: No such file or directory in /PATH/
PHP Warning: move_uploaded_file(): Unable to move '/tmp/phpKqDKMX' to '/Database/ARCHIVIOIMAGO/back.png' in /PATH/
How can I do?
Posted on 16 Aug 2022, this text provides information on Web Development related to Web Technologies. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.