Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    England =)
    Posts
    523
    Thanks
    26
    Thanked 0 Times in 0 Posts

    unlick issues, file deleted but can still access?!?

    Hi guys.

    i have an upload area that enables users to upload a file to the system. the file uploads fine, but if someone wants to create another file i want the initial file to delete then the new one to be added.

    there seems to be a weird caching issue somewhere.

    it lets me delete the initial file but when i click on the link it opens up the old version. is this due to caching?

    if i look in the folder (windows box running zendserver community edition) the new file is in the folder but i cant open it (access denied)

    code:
    PHP Code:
        if (is_file($uploadfile)){ //delete last version
            
    error_log("Found " $uploadfile0);
            if(
    unlink($uploadfile)) {
                
    error_log("deleted " $uploadfile0);
            } else {
                
    error_log("didnt delete " $uploadfile0);
            }        
        } else {
            
    error_log("Didnt find " $uploadfile0);
        } 
    arghhh! help plz!

    UPDATE: if i change the download link to {link}?date("y-n-j-H-i-s") it works fine, so im guessing its 100% a caching issue. obviously putting that random time stamp at the end stops IE from using a cached version. this isnt the most elegant workaround though. any ideas?
    Last edited by babelfish; 07-11-2011 at 11:22 AM.
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,441
    Thanks
    62
    Thanked 537 Times in 524 Posts
    Sounds like you're suffering with disk caching. Some hosts cache whilst others don't - no idea why or what the purpose of it is but its very annoying and i've suffered from it myself.

    Your best way forward is to give the files a random filename which you then store in the database with the real filename for reference purposes. When you need to delete the file you then delete it as normal but the next file that is uploaded with the same real filename gets a different random name - thus avoiding the issue.

    Your best bet would be to use a mixture of uniqid(), md5() and filemtime() to create a random filename for each uploaded file.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    England =)
    Posts
    523
    Thanks
    26
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tangoforce View Post
    Sounds like you're suffering with disk caching. Some hosts cache whilst others don't - no idea why or what the purpose of it is but its very annoying and i've suffered from it myself.

    Your best way forward is to give the files a random filename which you then store in the database with the real filename for reference purposes. When you need to delete the file you then delete it as normal but the next file that is uploaded with the same real filename gets a different random name - thus avoiding the issue.

    Your best bet would be to use a mixture of uniqid(), md5() and filemtime() to create a random filename for each uploaded file.
    maybe, but then when people download the file it has a stupid name, yes, i could rename it but thats an extra step. think i will keep the ?randomstuff as at least when it downloads you get the proper filename. i dont want to confuse my users, they arent brain surgeons!
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •