我如何在Perl中验证图像文件? [英] How can I validate an image file in Perl?

查看:115
本文介绍了我如何在Perl中验证图像文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何验证一个jpg文件是一个有效的图像文件。我们正在使用FTP将文件写入目录,但我们似乎在文件完成写入之前正在拾取文件,从而创建无效图像。我需要能够识别它不再被写入的时间。任何想法?

解决方案

您正在解决错误的问题,我想。



你应该做的是弄清楚如何判断你正在使用的FTPd是在写文件的时候 - 这样,当你对GIF,DOC或MPEG有相同的问题时,你不用您必须再次修复它。



准确地说,您如何做到这一点非常关键取决于您正在运行的操作系统的FTPd。如果您可以运行您自己的FTPd,Net :: FTPServer或POE :: Component,那么您可以设置一些钩子,以便在上传完成时触发。 :: Server :: FTP是可以自定义的做正确的事情。



如果没有:

1)尝试使用Perl脚本来查找日志,查找上传完成消息
2)使用类似于 lsof fuser 检查是否有任何内容正在锁定文件,然后再尝试复制它。


How would I validate that a jpg file is a valid image file. We are having files written to a directory using FTP, but we seem to be picking up the file before it has finished writing it, creating invalid images. I need to be able to identify when it is no longer being written to. Any ideas?

解决方案

You're solving the wrong problem, I think.

What you should be doing is figuring out how to tell when whatever FTPd you're using is done writing the file - that way when you come to have the same problem for (say) GIFs, DOCs or MPEGs, you don't have to fix it again.

Precisely how you do that depends rather crucially on what FTPd on what OS you're running. Some do, I believe, have hooks you can set to trigger when an upload's done.

If you can run your own FTPd, Net::FTPServer or POE::Component::Server::FTP are customizable to do the right thing.

In the absence of that:

1) try tailing the logs with a Perl script that looks for 'upload complete' messages 2) use something like lsof or fuser to check whether anything is locking a file before you try and copy it.

这篇关于我如何在Perl中验证图像文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆