在上传之前或期间检测损坏的 jpg 文件
我有一个 ASP 应用程序,它使用 ASPImage.Image 调整上传图像的大小,然后将文件保存到服务器并将其保存在数据库中。但是,如果用户上传损坏的文件,则生成的图像似乎是空白的白色图像。
我需要一种方法来在图像传递到 ASPImage.Image 之前检查文件是否损坏,然后通知用户文件已损坏。
这可以用 javascript、vbscript 或 ASPImage.Image 本身来完成吗?
任何帮助将不胜感激。
最好的问候,
保罗·雅各布斯
I have an ASP application that uses ASPImage.Image to resize the uploaded image and then save the file to the server and save it in the database. However, it appears that if a user uploads a corrupted file the resulting image is blank white image.
I need a way to check if the file is corrupted before the image is passed to ASPImage.Image, that will then inform the user that the file is corrupted.
Can this be done with javascript, vbscript or ASPImage.Image itself?
Any assistance would be greatly appreciated.
Best Regards,
Paul Jacobs
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
无法在 javascript 或 vbscript 中检测损坏的图像 - 您需要尝试使用
ASPImage.Image
。它有一个
Error
属性,这可能会出现一个错误,详细说明已加载损坏的文件 - 您尝试过吗?也就是说,如果它被填充,则该文件很可能已损坏。此外,
LoadImage
方法返回一个布尔值 - 我认为如果图像由于损坏而无法加载,它将返回 false。There is no way to detect a corrupt image in either javascript or vbscript - you will need to try using
ASPImage.Image
directly.It has an
Error
property, this will probably have an error detailing that a corrupt file has been loaded - did you try that? That is, if it is populated, chances are that the file was corrupt.Additionally, the
LoadImage
method returns a boolean - I assume it will return false if the image couldn't be loaded due to corruption.您可以在此处使用代码: http://forums.aspfree.com/code-bank-54/pure-asp-upload-script-with-additional-features-94647.html
然后检查图像的宽度和高度 - 如果为 0表示上传的文件不是有效的图像。
这是纯粹的经典 ASP 代码,没有第三方组件。
You can use the code here: http://forums.aspfree.com/code-bank-54/pure-asp-upload-script-with-additional-features-94647.html
Then check the image Width and Height - if 0 it means the uploaded file was not a valid image.
This is pure classic ASP code without third party components.