Heim > Backend-Entwicklung > PHP-Tutorial > 多文件上传[Flash]插件,PHP版的一个问题

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Freigeben: 2016-06-20 12:42:37
Original
1090 Leute haben es durchsucht

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;
?>


回复讨论(解决方案)

    $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"] 就是原始文件名



谢谢解释,看明白了,读取传入的流 方式时只有图片流信息,没有文件名信息
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage