• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

多文件上传[Flash]插件,PHP版的一个问题

php 搞代码 4年前 (2022-01-23) 35次浏览 已收录 0个评论
文章目录[隐藏]

http://www.cnblogs.com/zjfree/archive/2011/01/06/1929100.html
上面地址中,在内容说明中有个PHP上传代码,这个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://&#8217; . $_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;
?>

回复讨论(解决方案)

$rawpostdata = file_get_contents(“php://input”); //读取传入的流

$myfile = fopen($img_path, “w”) or die(“Unable to open file!”);
fwrite($myfile, $rawpostdata); //将得到的数据写入文件
fclose($myfile);

显然他本@文来源[email protected]搞@^&代*@码网(搞代gaodaima码并没有传递文件名,自然你也就得不到了
但如果视奏这个分支的
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”] 就是原始文件名

谢谢解释,看明白了,读取传入的流 方式时只有图片流信息,没有文件名信息


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:多文件上传[Flash]插件,PHP版的一个问题

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址