Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

advice on technology to use

Options
  • 24-06-2008 1:53pm
    #1
    Closed Accounts Posts: 117 ✭✭


    i need to setup a simple web form to collect data and send(ftp?) it to another network directory/server to be processed.

    the data needs to be captured in a particular format (probably in a txt file) so that when it reaches the correct directory it is processed properly.

    the txt file created needs to be a different filename everytime as i dont want msg1 overwriting msg2 when it gets delivered.

    eg
    the Form would include fields <date><time><from><type><msgtxt>

    when formated the text needs to look like this exactly with spaces dots etc:

    .<from> <date><time>
    -<type>
    -<msgtxt>

    i'm thinking of using asp/php to capture the data and write to a txt file and then ftp to send it to the directory.

    not exactly sure how to make it create a new named file everytime.

    any advice if i'm using the right stuff (asp or php) to do this or should i use something else (any links to resources?)

    thx in advance


Comments

  • Closed Accounts Posts: 94 ✭✭Done and dusted


    Hey,

    Well if your using ASP.net for this project you could use a system made GUID to create a unique id for each file. So you could have something like:

    CapturedData-SOMEGUID.txt

    If you want to do this in PHP i would use
    uniqid(rand(),true)
    

    in C# this would be done by
    System.Guid.NewGuid().toString();
    


  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    While random numbers and GUIDs tend to be the best way of doing this, it can make it tough to troubleshoot when you have a directory full of nonsense filenames.

    If you output a filename that contains a timestamp, it makes it clear when the file was created and the order in which it should be processed. There is a tiny risk of duplicating filenames, but this can be minimised.
    E.g.

    [php]<?php

    //This will output a filename which pin points the creation time down to the millsecond.
    //The output will be something like 'output_file_2008-06-24_15-00-00-52364.txt'
    $filename = "output_file_".date("Y-m-d_H-i-s-u");
    $data_path = "e:/path/to/dir/";

    if(file_exists($data_path.$filename.".txt")) {
    //Somehow the file exists, try to create a new one
    $max_inc = 100; //We specify a maximum increment so that the script doesn't execute forever in the case of weirdness
    $new_file_found = 0;
    $i = 1;

    while($i < $max_inc && !$new_file_found) {
    //add ($i) to the end of the filename and see if it exists
    if(file_exists($data_path.$filename."($i).txt")) {
    $i++;
    } else {
    $filename .= "($i)";
    $new_file_found = true;
    }
    }


    }

    $fh = @fopen($data_path.$filename.".txt", 'w');

    /*
    Write out the data
    */

    fclose($fh);

    ?>
    [/php]
    I'll probably be shot down for this though :)


  • Closed Accounts Posts: 94 ✭✭Done and dusted


    Taking aim at Seamus.............BANG! only kidding

    Both are valid solutions. TBH i think it depends on the environment that this will be used in. For instance if its going to be used in a system where there are constantly high usage of the application then personally I wouldn’t go with the timestamp idea.

    However to make sense of the nonsensical GUIDs why not incorporate both methods i.e. Filename + Guid + date.time.now() + ".txt" or something similar


  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    Both are valid solutions. TBH i think it depends on the environment that this will be used in. For instance if its going to be used in a system where there are constantly high usage of the application then personally I wouldn’t go with the timestamp idea.
    Agreed. I forgot to tack that onto the end of my post. My solution is good for a system where you'll only be writing out a new file from a single server at most every couple of minutes.

    If you need something that will be running every other second, or that will be running on multiple servers at the same time, then a more random method is desirable.
    However to make sense of the nonsensical GUIDs why not incorporate both methods i.e. Filename + Guid + date.time.now() + ".txt" or something similar
    Indeed this is probably the best solution.


  • Closed Accounts Posts: 94 ✭✭Done and dusted


    TEAM WORK FTW!! :)

    yeah I've actually used just GUID before for a logging system on a Very highly used server and I can tell you it was so painful trying to sift through logs files when the names meant nothing. So yes using both would be most recommended!


  • Advertisement
  • Closed Accounts Posts: 117 ✭✭jimmychin


    thanks Seamus/Done And Dusted,

    there will be high usage and there will be access from a number of different locations to the form (eg Dublin, London, Paris, Milan) so i was thinking of naming using the originator location (which would be in the form) and timestamp (and now random).


  • Closed Accounts Posts: 94 ✭✭Done and dusted


    Cool, no worries glad I could help!!

    Let us know if theres any implementation issues with the new method of name (shouldnt be...but ya never know)


    Happy Coding


Advertisement