Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Jun 2005
    Posts
    91
    Thanks
    19
    Thanked 0 Times in 0 Posts
    Code is;

    $target="c\test";

    $sql = " select * from test order by headnum ,arrangenum ";
    $test_result = mysql_query($sql);
    for ($i=0; $row=mysql_fetch_array($test_result); $i++)
    {
    $g_date = date("Y-m-d H:i:s", $row[g_date]);

    //file copy upgrade
    $file1 = "";
    $file1_source = "";
    echo "<'$target'>"; //no 1
    if ($row[files] && file_exists("$test[dir]/$row[files]")) {
    echo "<'$target'>"; // no 2
    echo($row[files]);
    }
    }

    no 1 line show right result, but no 2 line shows nothing.


    Any comment would be appreciated.

  • #2
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Shouldn't target be 'c:/test' ?
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #3
    New Coder
    Join Date
    Jun 2005
    Posts
    91
    Thanks
    19
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by marek_mar
    Shouldn't target be 'c:/test' ?
    No, target should be 'c:\test'.

    And, I tried
    $target="aa";

    But same result.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    1. $target is incorrect. Should be either C:\test or a relative path. I also see no reason for this to create the errors.
    2. $test is undefined.
    3. SQL may return an empty row, though I say its not simply due to the fact your first echo is returned. It is possible however, that the information is not complete.
    4. Is there a reason why you have this as: "<'$target'>"? Interior commas are probably unessessary, also assuming this is for XML generation.

    Also, you have an odd way of setting up your loop. Under the assumption that the data should always be present, you should just use:
    PHP Code:
    while ($row mysql_fetch_array($test_result))
    {
         
    // Stuff, no $i added for your arrays though...

    Edit: The last point is possibly the main cause of this, as you are not specifying where its location within the loop is. As well, if this is not the cause, its due to the attempt to grab $test[dir], which I assume is supposed to be $row['dir']. These two fixes should cause this to function correctly.
    Last edited by Fou-Lu; 06-30-2005 at 11:51 AM.

  • #5
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Well aren't backslashes windows only?
    In the code you are using the forward slash
    Code:
    file_exists("$test[dir]/$row[files]"))
    so you might stick to on type of slash (preferably the unix one as it will work on unix systems and on windows).
    In double quotes the "\" escapes some things but a "\t" inserts a horizontal tab so it's probably not what you want. If you wan't to use a backslash you should escape it so it would be "c:\\test".
    The loop is ok. It doesn't matter if it's a for or a while loop (though you don't usually use for loops for that).
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #6
    New Coder
    Join Date
    Jun 2005
    Posts
    91
    Thanks
    19
    Thanked 0 Times in 0 Posts
    copying files $souce/$testfiles to $target/$testfiles

    $source="/test-source";
    $target="/test-target";
    $target_dir="file_name";

    while ($row=mysql_fetch_array($test_result))
    {
    $file1 = "";
    $file1_source = "";
    if ($row[file_name1] && file_exists("$source/$row[file_name1]")) {
    $file1 = substr(md5($i),0,8) . "_" . $row[s_file_name1];
    $file1_source = $row[s_file_name1];
    echo "a-$file1"; <---- no1
    echo("b-$source/$row[file_name1]");
    echo("c-$target/data/file/$target_dir/$file1");
    @copy("$source/$row[file_name1]", "$target/data/file/$target_dir/$file1");
    @chmod("$target/$row[file_name1]", 0606);
    /* if (is_file($target/$row[file_name1])) {
    return echo $target/$row[file_name1]; } */
    } else {
    echo $row[s_file_name1];
    $file1 = substr(md5($i),0,8) . "_" . $row[s_file_name1];
    $file1_source = $row[s_file_name1];
    echo "d-$file1"; <---no2
    echo("e-$source/$row[file_name1]");
    echo("f-$target/data/file/$target_dir/$file1");
    @copy("$source/$row[file_name1]", "$target/$row[file_name1]");
    @chmod("$target/data/file/$target_dir/$file1", 0606);
    /* if (is_file($target/$row[file_name1])) {
    return echo $target/$row[file_name1];
    } */

    }
    }

    No1 shows nothing.
    No 2 shows
    d-:: eccbc87e
    e-:: /test-source
    f-:: /test-source/file_name/eccbc87e_

    Any comment would be appreciated.

  • #7
    New Coder
    Join Date
    Jun 2005
    Posts
    91
    Thanks
    19
    Thanked 0 Times in 0 Posts
    Dear Fou_Lu and marek_mar,

    Thanks alot for your kind comments.

    I've solved this by changing if sentence.


  •  

    Posting Permissions

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