Deleting the file from client PC after upload but

2020-04-23 06:47发布

问题:

I got a requirement from client to delete file from his local pc after upload. It should ask to user if he want to delete the file after successful upload. If user opted yes then file should be deleted from client pc.

I know this is not easy to achieve in web application while quite easy in desktop app.My client is upgrading from desktop app to web and expecting the same behavior.

I heard that any browser plugin or small utility installed on client machine can do that. I have seen few example in other website that client is referring.

Can someone please suggest me the plugin or utility logic that can help me to achieve this? And how we can interact with these stuff from our java script or code.

Thanks in advance.

Regards, Krishan

回答1:

Javascript/HTML5 alone can't do this, it's restricted to maintain a certain level of security. You will have to look into activeX plugins, and it will only work if the user runs the web app on IE.

Here is a short example:

<script type="text/javascript">  

    // initialize ActiveXObject with Scripting.FileSystemObject:  
    var activeX_FileSystemObject = new ActiveXObject("Scripting.FileSystemObject");  

    if(confirm("Delete file?"))
    {
        activeX_FileSystemObject.DeleteFile("C:\\myFolder\\myFile.txt", true);
    }

    // Another way (multiple files in a catalog):
    if(confirm("Delete file?"))
    {
        activeX_FileSystemObject.DeleteFile("C:\\myFolder\\*.txt", true);
    }

    activeX_FileSystemObject = null;  

 </script>

It's also possible that a Chrome plugin can do the same as the activeX, but never coded one myself - and it's also Chrome spesific.