PHP 文件未上传
我不太喜欢 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您不必使用
sys_get_temp_dir()
。$_FILES["files"]['tmp_name']
已经指向临时目录。因此,将您的代码更改为如下所示:
编辑:哦,您应该使用 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:
Edit: Oh, and you should use is_uploaded_file to check whether or not a file has been uploaded.
我看不到
$_POST['loanee']
在哪里设置,但它需要设置。否则有趣的代码就会被跳过。I don't see where
$_POST['loanee']
gets set, but it needs to be set. Otherwise the interesting code is just skipped.在 php 脚本的第一行,您检查应该来自 HTML 表单的
loanee
变量,但表单中没有任何具有该名称的字段。更具体:
要解决您的问题,请删除该语句控件或使用该名称在表单中添加一个新字段。
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 :
To solve your problem either remove that statement control or add a new field into your form with that name.