在PHP中查看文件信息?
我刚刚制作了一个文件上传表单,到目前为止我已经有了它,以便用户只能上传自己的.mp3;
目前,我的表单所做的就是将文件名更改为 $username 。 “-”。 $标题; 他们输入的变量;
然而,该表单仍处于测试阶段,我想知道是否有一种方法可以使用 PHP 查看文件信息(如果不是所有文件,则为 .mp3),然后使用 $username 和 $title 重写文件信息,以及用户的其他输入 - 即在上传文件之前。
我怎样才能这样做呢?
I have just made a file upload form, and so far I have it so that users can only upload their own .mp3's;
Currently, all my form does is change the filename to $username . " - " . $title; in which the variables they enter;
The form is still in beta, however, and I am asking if there is a way I can view the file information (for .mp3 if not all files) with PHP, and then rewrite the file information with the $username and $title, and additional inputs from the user - that is, before uploading the file.
How can I do so?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您可以使用 getID3() 解析器来获取 MP3 文件信息。
还有这些 ID3 PHP 函数可用。
You can use the getID3() parser to get MP3 file information.
There are also these ID3 PHP functions available.
这就是你所追求的吗? http://getid3.sourceforge.net/
Is this what you're after? http://getid3.sourceforge.net/
有多种方法可以做到这一点......有一个名为 id3 的 pecl ext,它允许您读取 mp3 文件并为其设置标签。
链接到 pecl:http://pecl.php.net/package/id3 ,也在此处是一个关于如何使用 ext....http://devzone.zend.com/article/4025-Reading-and-Writing-MP3-and-Photo-Metadata-with-PECL-
文件上未设置 mp3 标签,您可以随时尝试 ffmpeg 它将提供有关该文件的所有信息编码...还有一个围绕 ffmpeg 的 php 库,这可能很有用 http://sourceforge .net/projects/ffmpeg-phpclass/
The are various ways of doing this....there is a pecl ext called id3 which allows you to read and set tags to the mp3 file.
link to pecl:http://pecl.php.net/package/id3 , also here is a link to a nice tutorial on how to use the ext....http://devzone.zend.com/article/4025-Reading-and-Writing-MP3-and-Photo-Metadata-with-PECL-
Should the mp3 tags not be set on the file, you can always try ffmpeg which will give all the information about the file encoding ...there is also a php lib that wraps around ffmpeg which might be useful http://sourceforge.net/projects/ffmpeg-phpclass/
如果您无法安装 php id3 模块,您可以使用 此功能。
If you can't install the php id3 module you can use this function.
听起来您只是想重命名该文件。 如果是这种情况,你会这样做:
参考:https:// www.php.net/manual/en/function.rename.php
G-Man
It sounds like you're just trying to rename the file. If that's the case you'd do something like this:
Reference: https://www.php.net/manual/en/function.rename.php
G-Man
如果您确实询问是否可以“在上传文件之前”获取文件信息,那么不,您不能。 您无法从 Web 服务器读取客户端硬盘上的文件。 其他答案涵盖了文件上传后您可以执行的操作。
If you're really asking if you can get file information "before uploading the file," then No, you can't. You can't read files on a client's hard drive from a web server. Other answers cover what you can do after the file is uploaded.