PHP 文件未上传

发布于 2024-12-09 16:19:46 字数 1174 浏览 0 评论 0原文

我不太喜欢 PHP,但我不明白这有什么问题。大约 15 分钟前,我有同样的代码在运行,但现在它停止运行了。我没有改变任何东西,所以我有点困惑。

不管怎样,这是一个表单,你应该提交一个屏幕截图,这是我的表单的代码,

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

我不认为这有什么问题。这是处理所有这些的 PHP(我认为/希望)

 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");
    }
  }

我没有收到任何回显,并且错误日志中没有显示任何错误,那么出了什么问题?

感谢您的任何帮助。

Loanee不是问题,因为我的sql数据库在图片“上传”后正在更新,我没有放置整个表格,因为其中一些有一些我认为不必要的信息,表格工作正常正如我之前所说,对那些一直告诉我贷款人没有在表格中设置的人表示抱歉,事实是这样。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

〃安静 2024-12-16 16:19:46

您不必使用 sys_get_temp_dir()$_FILES["files"]['tmp_name'] 已经指向临时目录。

因此,将您的代码更改为如下所示:

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

编辑:哦,您应该使用 is_uploaded_file 检查文件是否已上传。

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.

北方的韩爷 2024-12-16 16:19:46

我看不到 $_POST['loanee'] 在哪里设置,但它需要设置。否则有趣的代码就会被跳过。

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

梦里兽 2024-12-16 16:19:46

在 php 脚本的第一行,您检查应该来自 HTML 表单的 loanee 变量,但表单中没有任何具有该名称的字段。

更具体:

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

要解决您的问题,请删除该语句控件或使用该名称在表单中添加一个新字段。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文