SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Addict isuru's Avatar
    Join Date
    Nov 2000
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could someone please explain this bit of code for me?

    I found it in a tutorial formerly found at Zend.com

    what does it do?

    Code:
    srand(microtime());
    $id=sprintf("%c%d",ord(?A?)+rand(0,26),time());
    $dirname="$filepath/$id";
    mkdir($dirname,0700);
    $filename=$dirname."/picture";
    $out=@fopen($filename,"w");

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It would appear that generates a random number then makes a dir with that random number then opens a file in that folder for writing
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Addict isuru's Avatar
    Join Date
    Nov 2000
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your help freddy

    could you please explain this bit of code as well? its from the same tutorial :

    Code:
    while($buffer=fread($fp, 8192)){
    	fwrite($out,$buffer);
    	}
    BTW freddy, do you have ICQ?

  4. #4
    SitePoint Evangelist mad-onion's Avatar
    Join Date
    Aug 2000
    Location
    Land of the long white cloud
    Posts
    556
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I can explain that if thats okay with you :-)

    while($buffer=fread($fp, 8192)){
    fwrite($out,$buffer);
    }

    ...that read 8192 bytes of the filehandle $fp and then writes it to the filehandle defined by $out...


    SiteOptions >> Services :: Products :: Contact
    Developers of PHP, C++, Visual Basic, MySQL, and more!

  5. #5
    SitePoint Addict isuru's Avatar
    Join Date
    Nov 2000
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot mad-onion

    but when the while loop goes a second time doesn't that mean whatever is in the $out variable gets replaced with the new values of the $buffer variable? or does the new values of the buffer variable get appended to the end of the $out variable?

    thanks

  6. #6
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It would just write the new value of $out right after the olde value and so on and so forth...
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  7. #7
    SitePoint Evangelist mad-onion's Avatar
    Join Date
    Aug 2000
    Location
    Land of the long white cloud
    Posts
    556
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The script is basically copying one file to another...
    So each time it loops it adds the value of buffer to the out file...

    SiteOptions >> Services :: Products :: Contact
    Developers of PHP, C++, Visual Basic, MySQL, and more!

  8. #8
    SitePoint Evangelist mad-onion's Avatar
    Join Date
    Aug 2000
    Location
    Land of the long white cloud
    Posts
    556
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I receieved email notification of freddies reply about .01 of a second after clicking submit...
    What is the probability?! (rhetorical question)
    SiteOptions >> Services :: Products :: Contact
    Developers of PHP, C++, Visual Basic, MySQL, and more!

  9. #9
    SitePoint Evangelist
    Join Date
    May 2000
    Location
    Canada
    Posts
    533
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the probability is... wait , no, lemme not say

    /me wonders where this thread is going to / coming from
    cogito, ergo sum


Bookmarks

Posting Permissions

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