Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 27
  1. #11
    Join Date
    Jun 2004
    Location
    USA
    Posts
    59
    ok first a question shamabaghodia....

    The scrip that you gave me on the jpg thing.

    When I load it to a server it has no problems at all. All I do is name the folder /users/pictures and the script does a great job.

    When I put the same script on the testing server using apache it gives me all sorts of errors. Any ideas as to why it does that?
    I tried using paths... exmaple: K:/server/pictures and no img is loaded and the path is all wrong. Also I noticed that the script will also use .txt as an img. Can we control that only to a format such as .jpg?

    About the array... Yeah... I understand (kinda). I don't understand about $key and $val.

    one more question there.... if you use array

    $BOOK[]

    and you were to retrive it from a line in a text file.

    Example.

    comments.txt
    -------------------------------------
    hello I am Teske.
    Hello number 2.
    Hello number 3

    if you were to load that text and wanted to delete line number two and still keep line 1,3 like you would do an EDIT... how would I go about doing it?


    Is this correct?
    -----------------------------------

    $BOOK[] = "a";
    $BOOK[] = "b";
    $BOOK[] = "c";

    $books = $BOOK[];
    sort($books);

    $count = count($books);

    echo "There are ".$count." books in books<BR>"
    echo "One of them is ".$BOOK[1];

  2. #12
    Join Date
    Mar 2003
    Location
    Santa Rosa, CA
    Posts
    49
    ERROR MSGS:
    It sounds like you are using a Windows server which I am not very familiar with being a Unix guy. Post the error messages and I will see if I can help.

    SORTING OUT JPEGS:
    Currently that script will grab all the files in the given folder except for ".." and "." (If your on Windows, don't worry about those). If you only want it to find jpegs, then we just add a little bit of code to sort out jpegs as we put them into the array.

    PHP Code:
    <?php
    $IMGS 
    = array();

    $d dir("yourFolder/");
    while (
    false !== ($entry $d->read())) {

        
    $goodFile true// Innocent until proven guilty
        
    if ($entry != ".."$goodFile false;
        if (
    $entry != "."$goodFile false;

        
    // Check if file has the .jpg or .jpeg extension
        
    if (strrchr(strtolower($entry), ".jpg") === false$goodFile false;
        if (
    strrchr(strtolower($entry), ".jpeg") === false$goodFile false;
        
        
    // If the file has passed all our checks, add to array
        
    if ($goodFile$IMGS[] = $entry;

    // while d->read
    $d->close();

    sort($IMGS); // Alpha Sort
    $count sizeof($IMGS); // Count IMGs

    if ($count 0) {
        
    ?><table cellpadding="5" cellspacing="0" border="0"><tr><?php
        
    for ($i 1; list($key$val) = each($IMGS); $i++) {
            if (
    $i == 1) echo "</tr><tr>";
            
    ?>
            <td>
                <a href="<?php echo $_SERVER['DOCUMENT_ROOT'].'/'.$val?>">
                <img src="<?php echo $_SERVER['DOCUMENT_ROOT'].'/'.$val?>"></a><br />
            </td>
            <?php
            
        
    // for each IMGS
        
    ?></tr></table><?php
    // count > 0
    ?>

    KEY AND VAL:
    About $key and $val: Every item in an array has a key and a value. The key is just a way for us to find a specific value in the array.
    list($key, $val) = each($ARRAY) just means grab the key and value of the current bookmarked item in the array, then advanced the bookmark to the next item in the array.


    DELETING LINES FROM A FILE:
    If you want to delete a specific line from a txt file, PHP has a great function to do just that. The file() function will grab the contents of a file and put them into an array.

    PHP Code:
    <?php
    $filename 
    "yourFolder/yourFile.txt";

    // Put the lines of a file into an array
    $lines file($filename);

    // Delete line number 2
    $lines[1] = "";

    // Put lines into a string
    $newContent implode(''$lines);

    // Write the newContent over the file
    if (is_writable($filename)) {
       if (!
    $handle fopen($filename'w')) echo "Cannot open file ($filename)";
       if (
    fwrite($handle$newContent) === FALSE) echo "Cannot write to file ($filename)";
       echo 
    "Successfully wrote ($newContent) to file ($filename)";
       
    fclose($handle);
    }
    else echo 
    "The file $filename is not writable";
    ?>
    Once you have the file lines into an array you can pretty much do anything you want with them. For more information on the file() function goto: http://us3.php.net/manual/en/function.file.php
    - shamabaghodia!

  3. #13
    Join Date
    Jun 2004
    Location
    USA
    Posts
    59
    Yup the server is running on a windows box. ^^;

    Warning: dir(D:\Server\structure est): failed to open dir: Invalid argument in D:\Server\structure\test\jpg_sort.php on line 4

    Fatal error: Call to a member function on a non-object in D:\Server\structure\test\jpg_sort.php on line 5



    Ok it says warning and the full path for the script is:

    D:\Server\structure\test\jpg_sort.php

    but the path for the pictures is:

    D:\Server\structure\test\pictures

    if I put a \ or a / it will still give me the same error.

    oh and line 4 and 5 are..

    $d = dir("D:\Server\structure\test\pictures");
    while (false !== ($entry = $d->read())) {


    On onother note... the other script worked like a charm.
    My script was driving me nuts on how to make it work. My first thought was:

    get all the posting using loop and then submit a table and then delete it from there but the problem that I would have was an empty row. It gave me a headache. but now... Sweet and easy... Thanks.


    I got this free server that lets me have php on it. It is running Lunix. Do I need anything special? I seen other sites say something about CHMOD. Will my script need that chmod thing in order to work?


    Thanks again and sorry about all the questions.

  4. #14
    Join Date
    Mar 2003
    Location
    Santa Rosa, CA
    Posts
    49
    I think you may need to escape your "\". Try typing: $lines = file("D:\\Server\\structure\\test\\pictures\\"); The backslash is used for escaping certain characters so itself must be escaped.

    Here is why:
    In order to specify a string I must use a ' or " to tell PHP when I want to start and stop my string. ( $str = 'my string'; )
    But what do I do when I have this: ( $str = 'don't do'; )? PHP now thinks I want to end my string after the n. So we fix it by escaping the apostrophe ( $str = 'don\'t do'; )
    I could of done this to fix it also: ( $str = "don't do"; ).


    CHMOD is a unix command for setting permissions. Window servers also have permissions but I'm not exactly sure how to set them, maybe right click on the folder and goto properties then permissions? But for just reading files from a folder you probably don't have to worry since most folders by default are setup with read permissions on.

    Don't be sorry about all the questions. I know little about windows servers and trying to answer your questions I am learning myself.
    - shamabaghodia!

  5. #15
    Join Date
    Jun 2004
    Location
    USA
    Posts
    59
    this is going to sound freaky but I wanted to know what the output was for the path each of those was taking and guess what...

    The path is supposed to be

    D:\server\structure\test\pictures


    the server was doing this:

    D:\server\structure est\

    I changed the folder name from test to work and everything works fine.

    having \test\ start \t and end t\ php doesn't seem to like it much.

  6. #16
    Join Date
    Jun 2004
    Location
    USA
    Posts
    59
    One more question and I am on my way to finishing this up....

    I got the $file to return lake.jpg

    how do I make it filter out the .jpg and just post "lake"

    example

    --------------------
    | |
    | PIC HERE |
    --------------------
    lake


    instead of having that type the full name of the pic lake.jpg.

  7. #17
    Join Date
    Dec 2002
    Location
    United Kingdom
    Posts
    635
    PHP Code:
    $_SERVER['DOCUMENT_ROOT'
    yet another cross platform problem

    In my experiance the above statement does not work at all on any windows based systems you will need to use thew following code that realy is a bit of a hack

    PHP Code:
    $DOCUMENT_ROOT str_replace
    (getenv "PATH_INFO"),"",str_replace
    ("\\","/",getenv "PATH_TRANSLATED"))); 
    now just substitute $_SERVER['DOCUMENT_ROOT'] with $DOCUMENT_ROOT in your scripts and it should be fine

    *edit*

    Please note however after using this little hack all your file paths will now use the unix/linux style of /

    i.e.
    path.to/you/file

    instead of
    C:\path\to\your\file

    document root dumps \path\to\file in windows for which php doesn't handel the \ properly hte above hack translates \ into / for php to use correctly
    Last edited by Sion; 06-14-2004 at 02:15 PM.
    Saiweb ~ Ramblings of a sysadmin

    My Current Recomended WebHost: Nativespace



    "Acies Latin: a sharp edge or point; mental acuity, sharpness of vision"

    NOTE: Acies is currently beta, the "down" page will be displayed untill I have finished a release candidate

    3DBuzz has a reputation system please rate posts using the icon

  8. #18
    Join Date
    Jun 2004
    Location
    USA
    Posts
    59
    Sion.... umm cool but I can only see half of your script. Is there any way that ou can cut it so I can see the rest of the code. Thanks.

  9. #19
    Join Date
    Mar 2003
    Location
    Santa Rosa, CA
    Posts
    49
    \t like \n and \r are escaped characters. \t actually means to put a tab space.

    To get rid of the .jpg and .jpeg do this:
    $file = str_replace(".jpg", "", $file);
    $file = str_replace(".jpeg", "", $file);
    - shamabaghodia!

  10. #20
    Join Date
    Dec 2002
    Location
    United Kingdom
    Posts
    635
    cut print that's a.....


    ok i'll shut up now




    edited you you can see the code enjoy
    Saiweb ~ Ramblings of a sysadmin

    My Current Recomended WebHost: Nativespace



    "Acies Latin: a sharp edge or point; mental acuity, sharpness of vision"

    NOTE: Acies is currently beta, the "down" page will be displayed untill I have finished a release candidate

    3DBuzz has a reputation system please rate posts using the icon

Page 2 of 3 FirstFirst 123 LastLast

Posting Permissions

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