在PHP中将文件名更改为uniqid [英] Change file name to uniqid in PHP
本文介绍了在PHP中将文件名更改为uniqid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
move_uploaded_file($ _ FILES [file] [tmp_name],
upload /。$ _FILES [文件名]);
$ ipath =upload /;
$ ipath。= $ _FILES [file] [name];
有谁知道我该如何做到这一点?编辑:我问在哪里把uniqid函数,以便该文件与uniqid.extension存储在我的服务器上的文件夹中。
解决方案
move_uploaded_file($ _ FILES [file] [tmp_name],
upload /。uniqid());
或者,如果您想保留文件扩展名:
$ fileInfo = pathinfo($ _ FILES [file] [name]);
move_uploaded_file($ _ FILES [file] [tmp_name],
upload /。uniqid()。'。'。$ fileInfo ['extension']);
\\\edit:使用$ ipath变量...
$ fileInfo = pathinfo($ _ FILES [file] [name]);
$ ipath =upload /。 uniqid()。 ''。 $的fileInfo [延伸];
move_uploaded_file($ _ FILES [file] [tmp_name],$ ipath);
I am looking to modify my code below to accept a randomly generated unique id to replace the name using php uniqid function. I have tried a couple ways with no success.
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
$ipath = "upload/";
$ipath .= $_FILES["file"]["name"];
Does anyone know how I can accomplish this?
Edit: I am asking where to put the uniqid function so that the file is stored with the uniqid.extension in the folder on my server.
解决方案
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . uniqid());
or, if you want to keep the file extension:
$fileInfo = pathinfo($_FILES["file"]["name"]);
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . uniqid() . '.' . $fileInfo['extension']);
\\edit: to use the $ipath variable...
$fileInfo = pathinfo($_FILES["file"]["name"]);
$ipath = "upload/" . uniqid() . '.' . $fileInfo['extension'];
move_uploaded_file($_FILES["file"]["tmp_name"], $ipath);
这篇关于在PHP中将文件名更改为uniqid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文