I am just trying to upload a file and nothing works.
<!DOCTYPE html>
<html><body>
<form id="exp" enctype = "multipart/form-data" action="../cgi-bin/uploadPic.php">
<input type="file" id="profilePic2" name="newPic"></input> <br /><br /><br />
<input type="submit" value="Upload Pic" style="color:black;"></input>
</form>
</body></html>
Running my php file. Please pay attention to the inaccurate code, I am trying to debug via echo.
<html>
<body>
<?php
$loadFile = true;
$allowedExts = array("jpg","jpeg","gif","png");
$extension = end(explode(".", $_FILES["newPic"]["name"]));
$file = $_FILES["newPic"];
$picIncluded = false;
if(( ($_FILES["newPic"]["type"] == "image/gif")
|| ($_FILES["newPic"]["type"] == "image/jpeg")
|| ($_FILES["newPic"]["type"] == "image/png")
|| ($_FILES["newPic"]["type"] == "image/pjpeg"))
&& ($_FILES["newPic"]["size"] < 5000000)
&& in_array($extension, $allowedExts)){
if($_FILES["newPic"]["error"] > 0){
echo "pnl";
}
else if(file_exists("../profile-pics/" . $file["name"])){
echo "pld";
} else {
$picIncluded = true;
echo "finally";
if(move_uploaded_file($file["name"]["tmp_name"],"./" . $file["name"])){
echo "Success again!";
}
$path = "../profile-pics/" . $file["name"];
}
}
if(is_uploaded_file($_FILES["newPic"]["name"]["tmp_name"])){
echo "Good news!";
}
?>
</body>
</html>
In any case, the move_uploaded_file () function returns false since it cannot find the temp file. is_uploaded_file () also returns false. My extensions and everything is correct, but still unsuccessfully, the file is not being downloaded. How can I debug this?
source
share