2011-05-14 111 views
0

我得到了一切,但这工作。我无法使move_uploaded_file();正常工作。php上传文件

$ups_path = "ups/files"; 
$nfile = $_FILES['nfile']['tmp_name']; 
$cfile = move_uploaded_file($nfile, $ups_path); 

if($cfile){ 
header ('Location: index.php?give=fileuploaded'); 
} else { 
header ('Location: index.php?give=filenotuploaded'); 
} 

它总是返回不移动它的错误。

+0

'$ ups_path'应该是绝对的。 – Orbling 2011-05-14 13:28:22

+2

*你得到了什么*错误?注意,'mysql_real_escape_string()'在这一点上没有用处。它不会删除文件名中的非法字符。 – 2011-05-14 13:28:24

+0

为什么在'tmp_name'上使用'mysql_real_escape_string'?可能你正在改变弦乐。检查是否是这种情况。 – 2011-05-14 13:33:47

回答

1

如果UPS /文件的目录,那么这将失败。 move_uploaded_file期望第二个参数是文件名,而不是目录。

+0

谢谢!接得好。我忘了让它像'$ ups_path =“ups/files/$ date_ $ filename”;'。我的脚本现在正在完成:) – yanike 2011-05-14 14:27:18

0

尝试使用绝对路径,而不是相对之一:

$ups_path = "/var/www/somewhere/ups/files";