1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Rep Power

    The sequence number for $filename

    Hi everyone, in the last few days, I tried to used Flash and PHP to make a program that can take photos with webcam and upload the photos into server folder.

    Inside my php code "$filename = "images1/visualstudio". mktime(). ".jpg";" is the reference I found online, I understand the "mktime()" was generating the combination of date and time,but what I really need is when the photos that upload to folder will be name with sequence number like: "visualstudio01.jpg","visualstudio02.jpg","visualstudio03.jpg"...

    Because this is the first time I deal with PHP, from my logic, the code should be "$filename = "images/visualstudio".SEQUENCE NUMBER CODE.".jpg";", but the problem is I don't know how the "SEQUENCE NUMBER CODE" structure should look like, can anyone give me some suggestion or some references?

    And here is my php code:
    [PHP CODE]

    //Now get the encoded image form flash through HTTP_RAW_POST_DATA
    $img = $_GET["img"];

    //image Directory
    $filename = "images1/visualstudio". mktime(). ".jpg";
    file_put_contents($filename, $jpg);
    } else{
    //show error if image is not recived
    echo "Encoded JPEG information not received.";
    [/PHP CODE]

    Thanks for your time !!
  2. #2
  3. Mad Scientist
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2007
    North Yorkshire, UK
    Rep Power
    this sounds like homework/tutorial stuff, so I'll give you some general pointers

    Straight forward method assuming no files are deleted:

    scandir() will return an array of all files within the folder, including the two special file "." and ".."

    count() counts the number of elements in an array

    (a combination of the two funstions will give you the next number in the sequence).

    Then, there's sanity checking:

    file_exists() will tell you if a file exists or not (you probably don't want to over write an existing file)

    then there's the infinite loop:

    PHP Code:
    $i 0;

    true) {
    /*condition*/) {
    //do something
    break; //break out of infinite loop

    //optionally put in a fail safe condition to ensure the loop does end!

    a combination of all these concepts will give you something you can rely on

    hint - to format your code like I have, write the code first (or paste it in) then select it all and click the white PHP button next to the # button in the formatting toolbar of the editor (the purple php button links to the manual)
    Last edited by Northie; October 17th, 2013 at 02:35 AM.
    I said I didn't like ORM!!! <?php $this->model->update($this->request->resources[0])->set($this->request->getData())->getData('count'); ?>

    PDO vs mysql_* functions: Find a Migration Guide Here

    [ Xeneco - T'interweb Development ] - [ Are you a Help Vampire? ] - [ Read The manual! ] - [ W3 methods - GET, POST, etc ] - [ Web Design Hell ]

IMN logo majestic logo threadwatch logo seochat tools logo