Not signed in (Sign In)

Vanilla 1.1.10 is a product of Lussumo. More Information: Documentation, Community Support.

    • CommentAuthorsnow
    • CommentTimeFeb 7th 2006
     
    Hi folks... I'd like to add a small function to admin/plog-upload.php to just check that there isn't already a file with the same name in the target album... Plogger doesn't seem to like that very much...

    I'll need something in the

    // Check if update has been clicked, handle erroneous conditions, or upload

    section like this:

    else if ($_FILES["userfile"]["name"] == " ***the name of a file in the target album*** "){
    $output .= '<p class="errors">That file already exists!</p>';
    }

    but I just can't get my head around the function that checks the filenames... I'm not sure where Plogger keeps the function that does this... Anyone better acquainted with the dear piece of software than I am that can point me in the right direction?
    • CommentAuthorddejong
    • CommentTimeFeb 7th 2006
     
    elseif(file_exists("images/" . $album . "/". $_FILES["userfile"]["name"]){
    $output .= '

    That file already exists!

    ';
    }

    Do you understand the methodology there? It won't be verbatim, but that's the idea.

    Cheers,
    Derek
    • CommentAuthorsnow
    • CommentTimeMar 7th 2006
     
    Thank you derek! I wasn't aware of the file-exists function.

    How come it's not just:

    elseif(file_exists($_FILES["userfile"]["name"])){
    $output .= '
    That file already exists!

    ';
    }

    the stuff before the file name part seems to be trying to target the correct folder, am I right? I've tried:

    (file_exists("images/" . $album . "/". $_FILES...

    and

    (file_exists("../images/" . $album . "/". $_FILES...

    and

    (file_exists("../images/" . $collection . "/" . $album . "/" . $_FILES...

    would have thought one of these would work...

    (you are speaking to a complete beginner here, by the way... I can't be offended by any assumptions about my knowlege, It's too lacking for that!)
    • CommentAuthorddejong
    • CommentTimeMar 7th 2006
     
    Well, the best reference for the novice php programmer is the manual itself:
    http://www.php.net/manual/en/

    Lots of examples, assortment of searches and great user comments.

    If you need help, let us know.

    Regards,
    Derek
    • CommentAuthorsnow
    • CommentTimeMar 19th 2006
     
    I've also tried:

    if (file_exists($sysfolder . '/' . $filename)) {
    // append a digit to the beginning of the name
    $tmpVar = 1;
    while(file_exists($sysfolder . '/' . $tmpVar . '-' . $filename)) {
    // and keep increasing it until we have a unique name
    $tmpVar++;
    }
    $filename= $tmpVar . '-' . $filename;
    }

    again, obviously, not my code, but pinched shamelessly from another helpful poster elsewhere... This is kind of fun, I'm gonna keep trying, hopefully learn some more code on the way.
    • CommentAuthorddejong
    • CommentTimeMar 20th 2006
     
    Looks good, though I would append to the end, so that when you sort by filename, all of the filenames that began together stay together (e.g. all the "soccer" or "platapus" photos are grouped together).

    Cheers,
    Derek
    • CommentAuthorsnow
    • CommentTimeMar 21st 2006 edited
     
    true... but not so much at the end that it adds it after the file extension causing problems... so we have to look at the name, determine how many . there are, and put it before the first one? or is it enough to just put it before the .

    keeping those platypuses together sounds like a good idea though, I'm not sure I'd like them to all be wandering around just anywhere :-s

    anyway, it's not working as of yet, I'll let you know if i get it to... Not sure that $sysfolder is correct...
    • CommentAuthorsnow
    • CommentTimeApr 21st 2006
     
    Okay, going back to:

    else if(file_exists("images/" . $album . "/" . $_FILES["userfile"]["name"])){
    $output .= '<p class="errors">That file already exists!</p>';
    }

    I've finally managed to get it to return the error message!
    If it's:

    else if(file_exists($_FILES["userfile"]["tmp_name"])){
    $output .= '<p class="errors">That file already exists!</p>';
    }

    It will return the error... However, it always returns the error, even if there is no file there.

    However, as soon as I put any "targeting" in, the error never appears, even if it's just:

    (file_exists("images/" . $_FILES["userfile"]["tmp_name"])

    hmm... Sorry, just thinking aloud really... to be continued...