PHP:文件上传move_uploaded_file()不起作用 [英] PHP: File upload move_uploaded_file() not working

查看:223
本文介绍了PHP:文件上传move_uploaded_file()不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是做了一个文件上传代码,我想知道为什么文件上传不起作用。我将上传目录更改为0777.这是我上传的HTML代码:

 < form action =upload_file.php方法=postenctype =multipart / form-data> 
< label for =file>文件名:< / label>
< input type =filename =fileid =file/>
< br />
< input type =submitname =submitvalue =Submit/>
< / form>

和PHP代码:

 <?php 
if($ _FILES [file] [error]> 0){
echoError Code:。 $ _FILES [file] [error]。 < br />;
}
else
{
echo上传的文件:。 $ _FILES [file] [name]。 < br />;
回显类型:。 $ _FILES [file] [type]。 < br />;
回声大小:。 ($ _FILES [file] [size] / 1024)。 kilobytes< br />;
$ b $ if(file_exists(/ files /\".$_ FILES [file] [name]))
{
echo $ _FILES [file] [ 名称] 。 已经存在,没有开玩笑 - 这个错误几乎不可能< / b>< / i>得到,再试一次,我打赌一百万美元,它不会再发生。 ;


$ $ b $ move_uploaded_file($ _ FILES [file] [tmp_name],/ filebro /\".$_ FILES [file] [name ]);
回声完成;
}
}
?>

那么,问题可能是什么呢? h2_lin>解决方案

试试

  move_uploaded_file($ _ FILES [file] [tmp_name ], filebro /\".$_ FILES [ 文件] [ 名称]); 


I just made a file upload code and I was wondering why the file upload wasn't working. I changed the upload dir to 0777. This is my upload HTML code:

<form action="upload_file.php" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" /> 
<br />
<input type="submit" name="submit" value="Submit" />
</form>

And PHP Code:

<?php
if ($_FILES["file"]["error"] > 0){
echo "Error Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Uploaded file: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kilobytes<br />";

if (file_exists("/files/".$_FILES["file"]["name"]))
  {
  echo $_FILES["file"]["name"] . " already exists. No joke-- this error is almost <i><b>impossible</b></i> to get. Try again, I bet 1 million dollars it won't ever happen again.";
  }
else
  {
  move_uploaded_file($_FILES["file"]["tmp_name"],"/filebro/".$_FILES["file"]["name"]);
  echo "Done";
  }
}
?>

So, what could the problem possibly be?

解决方案

Try

move_uploaded_file($_FILES["file"]["tmp_name"],"filebro/".$_FILES["file"]["name"]);

这篇关于PHP:文件上传move_uploaded_file()不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆