SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 43 of 43
  1. #26
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,057
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Yep, find out what permission is on the folder.
    ls -la foldername

    Next try to give the folder write access to everyone
    chmod 0777 foldername

    Then run your script in apache again and see if it generates the file for output. If it does, you have a permission issue. If it doesn't, something else is going on and I'm not sure what.
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  2. #27
    SitePoint Zealot
    Join Date
    Jan 2013
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cpradio View Post
    Yep, find out what permission is on the folder.
    ls -la foldername

    Next try to give the folder write access to everyone
    chmod 0777 foldername

    Then run your script in apache again and see if it generates the file for output. If it does, you have a permission issue. If it doesn't, something else is going on and I'm not sure what.
    SUCCESS! thanks man.^^,

  3. #28
    SitePoint Zealot
    Join Date
    Jan 2013
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cpradio View Post
    should be able to, it looks to be just ascii text.

    So you'd connect to the database, read the data, and use file_put_contents() to write the data to a file.
    How if that .txt file which already have the content of all the number below and i wanted to put it back to the mysql database? i tried but cant. i declare it as a longtext in database. is it right?

    UPDATE: SOLVED.^^,

  4. #29
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,057
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    keep in mind, it may be better for you to create a new group and give both your username and www-data access to that group (see the usermod command we referenced earlier). Once both of you are in that group you could do the following:

    addgroup newgroupname
    *use the usermod command we referenced earlier using the newgroupname for both your username and www-data*
    chown www-data.newgroupname foldername
    *restart apache*

    Then you should be able to leave the folder permission at 0755 (or 0775 if your user still needs permission)
    chmod 0755 foldername
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  5. #30
    SitePoint Zealot
    Join Date
    Jan 2013
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cpradio View Post
    keep in mind, it may be better for you to create a new group and give both your username and www-data access to that group (see the usermod command we referenced earlier). Once both of you are in that group you could do the following:

    addgroup newgroupname
    *use the usermod command we referenced earlier using the newgroupname for both your username and www-data*
    chown www-data.newgroupname foldername
    *restart apache*

    Then you should be able to leave the folder permission at 0755 (or 0775 if your user still needs permission)
    chmod 0755 foldername

    Ok sure i will. i have a post for you at #28

  6. #31
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,057
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Marvin_G View Post
    How if that .txt file which already have the content of all the number below and i wanted to put it back to the mysql database? i tried but cant. i declare it as a longtext in database. is it right?

    UPDATE: SOLVED.^^,
    You would need to use file_get_contents() and then write an update/insert statement (whichever is applicable). The type of column you use would be based on how much data you need to store and the type of data. If it is ascii characters and will be fairly lengthly, then text/longtext is just fine
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  7. #32
    SitePoint Zealot
    Join Date
    Jan 2013
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cpradio View Post
    You would need to use file_get_contents() and then write an update/insert statement (whichever is applicable). The type of column you use would be based on how much data you need to store and the type of data. If it is ascii characters and will be fairly lengthly, then text/longtext is just fine
    Hello there, i've met a new problem, in my .txt file i have this:

    \xf5\x00\x00\x00\x1c\x0b\x23\xda\x01\x0f\x96\x17\x61\x12

    but when i insert it into the database from "$file = file_get_contents('./results_eigenvalue.txt');", it worked, but it appear to be like:

    xf5x00x00x00x1cx0bx23xdax01x0fx96x17x61x12

    The slash are gone. how to fix this??


    UPDATE: i found out that it is because the magic quotes so i use this command "set_magic_quotes_runtime(true);" in my php file then it can display the "\" symbol. Is it a good method?

  8. #33
    SitePoint Zealot
    Join Date
    Jan 2013
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Second problem is after i get my data from database and tried to put it into a .txt file,it does not working. below is my code:

    <?php

    $con = mysql_connect("localhost","root","880702");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }

    mysql_select_db("FYP", $con);

    $sql="SELECT * FROM STUDENT_DATA";

    $result = mysql_query($sql);

    while($row = mysql_fetch_array($result))
    {
    $name = $row['Name'] ;
    $id = $row['IDNumber'];
    $eigenvalue = $row['Eigenvalue'];
    $chk = $row['CHK'];
    }

    mysql_close($con);


    echo $name."<br>";
    echo $id."<br>";
    echo $eigenvalue."<br>";
    echo $chk."<br>";


    $file = 'eigen_from_database.txt';
    // Open the file to get existing content
    $current = file_get_contents($eigenvalue);
    // Write the contents back to the file
    file_put_contents($file, $current);

    echo ("SUCCESS!!");

    ?>

    after taking from database i did echo all to make sure i get the data, although i get the correct data but still unable to transfer it into .txt file.


    UPDATE: Problem solved! i use below command:

    $myFile = "eigen_from_database.txt";
    $fh = fopen($myFile, 'w') or die("can't open file");
    fwrite($fh, $eigenvalue);
    fclose($fh);

  9. #34
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,057
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Marvin_G View Post
    Second problem is after i get my data from database and tried to put it into a .txt file,it does not working. below is my code:



    after taking from database i did echo all to make sure i get the data, although i get the correct data but still unable to transfer it into .txt file.


    UPDATE: Problem solved! i use below command:

    $myFile = "eigen_from_database.txt";
    $fh = fopen($myFile, 'w') or die("can't open file");
    fwrite($fh, $eigenvalue);
    fclose($fh);
    Your issue was this
    PHP Code:
    $current file_get_contents($eigenvalue);
    // Write the contents back to the file
    file_put_contents($file$current); 
    You don't need file_get_contents in this situation, you already had the value. You simply needed
    PHP Code:
    file_put_contents($file$eigenvalue); 
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  10. #35
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,057
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Marvin_G View Post
    UPDATE: i found out that it is because the magic quotes so i use this command "set_magic_quotes_runtime(true);" in my php file then it can display the "\" symbol. Is it a good method?
    Hmm.. I typically leave magic_quotes turned off and use $value = addslashes($value); (this may be a good question in a new thread to get various opinions on which is better practice)
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  11. #36
    SitePoint Zealot
    Join Date
    Jan 2013
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cpradio View Post
    Hmm.. I typically leave magic_quotes turned off and use $value = addslashes($value); (this may be a good question in a new thread to get various opinions on which is better practice)
    Hello there,i have a php code which will execute two C file. The way it run is like this, after i exec the matching_fingerprint, it took about 3 sec. then it will output a result in a .txt file. Second execution which is "check_matching_result" will use that particular .txt file to give result which is "OK" or "GG". The thing is, when i run it in terminal. it can detect correctly even if i switch finger, but when i run the same file in php using the code below, it will either echo JUST "fingerprint matched" or JUST "error". why is that happening?

    <?

    exec('./matching_fingerprint');

    sleep(5);

    $matching_status = exec('./check_matching_result');

    if ($matching_status == "OK")
    {
    echo ("FINGERPRINT MATCHED! THANK YOU!"."<br>");
    }
    else
    {
    echo ("ERROR: FINGERPRINT NOT MATCHED! TRY AGAIN!"."<br>");
    }

    ?>

  12. #37
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,057
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Kind of hard to answer that... but I'd start off pointing exec will only return the LAST line outputted by the script/program you call. So if a prior line contains the data you seek, then you won't get the expected response you want.

    You may want to use exec's second parameter (output) so you can get ALL of the output and can find the data you seek.
    http://us1.php.net/manual/en/function.exec.php
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  13. #38
    SitePoint Zealot
    Join Date
    Jan 2013
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cpradio View Post
    Kind of hard to answer that... but I'd start off pointing exec will only return the LAST line outputted by the script/program you call. So if a prior line contains the data you seek, then you won't get the expected response you want.

    You may want to use exec's second parameter (output) so you can get ALL of the output and can find the data you seek.
    http://us1.php.net/manual/en/function.exec.php
    Maybe i didn't clear up my buffer inside my C code,but the problem why it respond well when executing it in terminal rather than in php. Hurm..I need time to figure this thing out. Anyway, thanks man.

  14. #39
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,057
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    I'd capture the entire output and output that in var_dump from within your web application (using the second parameter of the exec statement). Something may be running differently and giving you unexpected data back.
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  15. #40
    SitePoint Zealot
    Join Date
    Jan 2013
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cpradio View Post
    I'd capture the entire output and output that in var_dump from within your web application (using the second parameter of the exec statement). Something may be running differently and giving you unexpected data back.
    i did this "$matching_status = exec('./check_matching_result'); var_dump($matching_status);" and i did really received the correct data thou. Still finding the problem why.

  16. #41
    SitePoint Zealot
    Join Date
    Jan 2013
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    for the same C file, i can execute it in terminal successfully but when i use exec('./"my c file"') in php, it can't run. why is that?? it only run half of my C code and when it comes to fopen --> to open .txt file, it stops there.

  17. #42
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,057
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    likely a permission issue. When you run it as yourself you have adequate permissions, but running it under apache, you might not. What is the owner/group of the file you are trying to open? And if you change the owner/group to www-data does it work?

    To see who is the owner/group
    Code:
    ls -la file.txt
    To change the owner/group
    Code:
    chown www-data.www-data file.txt
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  18. #43
    SitePoint Zealot
    Join Date
    Jan 2013
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cpradio View Post
    likely a permission issue. When you run it as yourself you have adequate permissions, but running it under apache, you might not. What is the owner/group of the file you are trying to open? And if you change the owner/group to www-data does it work?

    To see who is the owner/group
    Code:
    ls -la file.txt
    To change the owner/group
    Code:
    chown www-data.www-data file.txt

    THANKs for pointing it out. I changed it already and fixed my problem. Thank you so much bro. ^^


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
  •