开发者

PHP file not uploading

开发者 https://www.devze.com 2023-04-13 03:18 出处:网络
I don\'t mess with PHP alot, but I don\'t see what\'s wrong with this. I had this sa开发者_开发百科me exact code working about 15 minutes ago, but now it just stopped working. I didn\'t change anythin

I don't mess with PHP alot, but I don't see what's wrong with this. I had this sa开发者_开发百科me 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.


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.


I don't see where $_POST['loanee'] gets set, but it needs to be set. Otherwise the interesting code is just skipped.


At the first line of your php script you check for the loanee variable that is supposed to come from the HTML Form, but you don't have any field in your form with that name.

More specific :

if(isset ($_POST['loanee'])) {    // That line does not correspond to any input element into your form

To solve your problem either remove that statement control or add a new field into your form with that name.

0

精彩评论

暂无评论...
验证码 换一张
取 消