http://www.cnblogs.com/zjfree/archive/2011/01/06/1929100.html
上面地址中,在内容说明中有个php上传代码,这个php代码要怎么取得原文件名?
php代码:
$file_name = date('ymd') . '_' . time() . '_' . mt_rand(1, 1000) . '.jpg';
$file_path = '/img/user_img/' . date('y_m') . '/';
$dir = dirname(__file__) . $file_path;
//创建目录失败
@mkdir($dir, 0777, true);
$img_path = $dir . $file_name;
$img_url = 'http://' . $_server["http_host"] . $file_path . $file_name;
if (count($_files) > 0)
{
$f = current($_files);
move_uploaded_file($f["tmp_name"], $img_path);
}
else
{
$rawpostdata = file_get_contents("php://input");
$myfile = fopen($img_path, "w") or die("unable to open file!");
fwrite($myfile, $rawpostdata);
fclose($myfile);
}
echo $img_url;
?>
在原版的基础上做了一下修正:增加1st在线支付功能与论坛用户数据结合,vip也可与论坛相关,增加互动性vip会员的全面修正评论没有提交正文的问题特价商品的调用连接问题删掉了2个木马文件去掉了一个后门补了SQL注入补了一个过滤漏洞浮动价不能删除的问题不能够搜索问题收藏时放入购物车时出错点放入购物车弹出2个窗口修正定单不能删除问题VIP出错问题主题添加问题商家注册页导航连接问题添加了导航FLASH源文
立即学习“PHP免费学习笔记(深入)”;
回复讨论(解决方案)
$rawpostdata = file_get_contents("php://input"); //读取传入的流
$myfile = fopen($img_path, "w") or die("Unable to open file!");
fwrite($myfile, $rawpostdata); //将得到的数据写入文件
fclose($myfile);
显然他并没有传递文件名,自然你也就得不到了
但如果视奏这个分支的
if (count($_FILES) > 0)
{
$f = current($_FILES);
move_uploaded_file($f["tmp_name"], $img_path);
}
$f["name"] 就是原始文件名
$rawpostdata = file_get_contents("php://input"); //读取传入的流
$myfile = fopen($img_path, "w") or die("Unable to open file!");
fwrite($myfile, $rawpostdata); //将得到的数据写入文件
fclose($myfile);
显然他并没有传递文件名,自然你也就得不到了
但如果视奏这个分支的
if (count($_FILES) > 0)
{
$f = current($_FILES);
move_uploaded_file($f["tmp_name"], $img_path);
}
$f["name"] 就是原始文件名
谢谢解释,看明白了,读取传入的流 方式时只有图片流信息,没有文件名信息










