PHP上传后如何获取文件的SHA
我有一个站点,可以将文件从 URL 复制到我的服务器。我需要一种在复制文件后获取文件 SHA 的方法。
我使用 @copy($url,$upload_path)
复制文件,但这返回一个布尔值,我需要返回文件的东西。有这样的东西存在吗?
我需要稍后获取 sha1_file($file)
文件
谢谢!
I have a site which copies a file from a URL to my sever. I need a way of getting a SHA of the file after it has been copied.
I was using @copy($url,$upload_path)
to copy the file but this returns a boolean I need something that returns the file. Does anything like that exist?
I need to get the file afterwards for sha1_file($file)
Thank!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只需
$upload_path
已包含需要传递给sha1_file()
的值即可。而且,作为一般规则,
@
运算符是邪恶的。我承认它的这种特殊用法可以说是有效的,但根据经验,它应该被视为最后的手段。You can just
$upload_path
already contains the value you would need to pass tosha1_file()
.And, as a general rule, the
@
operator is evil. I will admit that this particular usage of it is arguably valid, but as a rule of thumb it should treated as a last resort.sha1_file
采用文件名。您提供的用于复制的$upload_path
是一个文件名。您应该能够执行以下操作:获取您的 sha1。
sha1_file
takes a filename. The$upload_path
you've supplied to copy is a filename. You should be able to do:to get your sha1.