Austin Austin - 1 month ago 6
PHP Question

PHP file not uploading

I don't mess with PHP alot, but I don't see what's wrong with this. I had this same exact code working about 15 minutes ago, but now it just stopped working. I didn't change anything, so I'm a little confused.

Anyways, It's a form and you are supposed to submit a screenshot, here's the code for my form,

<form method="post"
enctype="multipart/form-data">
<label for="file">Screenshot of them agreeing to terms:</label>
<input type="file" name="file" id="file" /> <br />
<input type="submit" name="submit" value="Submit" />
</form>


I don't think anything is wrong with that. Here's the PHP that handles all this (I think/hope)

if(isset ($_POST['loanee'])) {
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg")))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
$name = md5_file(sys_get_temp_dir() . $_FILES['tmp_name']);
move_uploaded_file(sys_get_temp_dir() . $_FILES["files"]['tmp_name'], "public_html/mc/images/{$name}.jpeg");
}
}


I am not getting anything echoed to me, and no errors are showing up in the error log, so what's wrong?

Thanks for any help.

Loanee is not the problem, as my sql database IS being updated after the picture is "uploaded", I didn't put the whole form, as some of it has some information I don't think is necessary, the form is working fine as I said before, sorry to everyone that keeps telling me that loanee isn't set in the form, it is.

Answer

You don't have to use sys_get_temp_dir(). The $_FILES["files"]['tmp_name'] will already point to the temp dir.

So change your code to something like this:

$name = md5_file($_FILES["file"]['tmp_name']);
move_uploaded_file($_FILES["file"]['tmp_name'], "public_html/mc/images/{$name}.jpeg");

Edit: Oh, and you should use is_uploaded_file to check whether or not a file has been uploaded.