Announcement

Collapse
No announcement yet.

Document (File Name) INSERT ERROR ?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Document (File Name) INSERT ERROR ?

    (1)Txt file, drag it area.
    (2)Txt file saved under a different name in the same folder tmp.





    PHP Code:
    $dizin 'C:/Program Files/NetMake/v7/wwwroot/scriptcase/tmp/';
    $filelocation $dizin.{text_file};    
    $file fopen($filelocation"r") or exit("Unable to open file!");
    //Output a line of the file until the end is reached
    while(!feof($file))
    {
        
    $satir fgets($file);
        
    //echo $satir . "<br />";
        
    $esr trim($satir);
        
    $ad trim(substr($satir05));
        
    $soyad trim(substr($satir59));

        
    // SQL statement parameters
        
    $insert_table  't2';      // Table name
        
    $insert_fields = array(   // Field list, add as many as needed
             
    'ad'  => "'$ad'",
             
    'soyad'  => "'$soyad'"
              
    );

    // Insert record
    $insert_sql 'INSERT INTO ' $insert_table
        
    ' ('   implode(', 'array_keys($insert_fields))   . ')'
        
    ' VALUES ('    implode(', 'array_values($insert_fields)) . ')';
    sc_exec_sql($insert_sql);    
    }
    fclose($file); 




    There is a error in the picture below.









    My questions:

    1 - fopen() how should i create the code to use the tmp folder path of the txt file?

    2 - How can i capture the name of the txt file name created and how?
    Last edited by castiel; 10-16-2013, 10:29 AM.

  • #2
    Afaik there's no way to manipulate the filename although this is a strong wish of many of us. The only thing you can interfer in is the path the document is stored into. You can use global varialbles or screenvariable for example. We use that to store files on personal numbers.
    Albert Drent
    aducom software netherlands
    scriptcase partner, reseller, support and (turn-key) development
    www.scriptcase.eu / www.scriptcase.nl

    Comment


    • #3
      Originally posted by aducom View Post
      Afaik there's no way to manipulate the filename although this is a strong wish of many of us. The only thing you can interfer in is the path the document is stored into. You can use global varialbles or screenvariable for example. We use that to store files on personal numbers.

      I can do it. Thank you very much.

      This is my solution.


      onBeforeInsert
      PHP Code:
      $filelocation 'C:/Program Files/NetMake/v7/wwwroot/scriptcase/tmp/';
      $ara=(glob($filelocation."sc_*.txt"));
      $file fopen($ara[0], "r") or exit("Unable to open file!");
      //Output a line of the file until the end is reached
      while(!feof($file))
      {
          
      $satir fgets($file);
          
      //echo $satir . "<br />";
          
      $esr trim($satir);
          
      $ad trim(substr($satir05));
          
      $soyad trim(substr($satir59));

          
      // SQL statement parameters
          
      $insert_table  't2';      // Table name
          
      $insert_fields = array(   // Field list, add as many as needed
               
      'ad'  => "'$ad'",
               
      'soyad'  => "'$soyad'"
                
      );

      // Insert record
      $insert_sql 'INSERT INTO ' $insert_table
          
      ' ('   implode(', 'array_keys($insert_fields))   . ')'
          
      ' VALUES ('    implode(', 'array_values($insert_fields)) . ')';
      sc_exec_sql($insert_sql);    
      }
      $file=$ara[0]; 
      onAfterInsert
      PHP Code:
      if(file_exists($file))
      {
          
      unlink($file);
          echo 
      $file ,"silindi";
      }else{
          echo 
      "bu isimde bir dosya yok:".$file;

      What is your opinion?
      Last edited by castiel; 10-16-2013, 01:02 PM.

      Comment


      • #4
        I haven't looked into it yet well, but you change the filenames in the tmp dir and add the filenames into the database? But the files in the tmp directory are moved to the final directory afterwards. Afaik that's the way php does it. That goes well too? Looks like a good option then.
        Albert Drent
        aducom software netherlands
        scriptcase partner, reseller, support and (turn-key) development
        www.scriptcase.eu / www.scriptcase.nl

        Comment


        • #5
          You should NOT change the file in the tmp dir. This is the name of the file of the file after the upload is done BEFORE the data is committed. If you normally save your data then via some save button then the file will be moved and renamed form the tmp dir to your regular upload dir. So you do have to point to an upload dir. No upload dir means that the file is stored in a subdir of the dir of the app somewhere. (img as I recall corerctly but I may be mistaken for that)

          Comment


          • #6
            Document (File Name)

            I solved the problem. How do you think happened ? Do you have the solution you think of it ?

            onLoad

            PHP Code:
            $yol1='C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/_lib/tmp/';
            $yol2='C:/Program Files/NetMake/v7/wwwroot/scriptcase/tmp/';

            $filelocation_onLoad =$yol2;
            $ara_onLoad=(glob($filelocation_onLoad."sc_*_*.txt"));
                
            $toplam_onLoad=count($ara_onLoad);
                    for ( 
            $say=$say $toplam_onLoad $say++ )
                        {
                        
            $file_onLoad=$ara_onLoad[$say];
                            if(
            file_exists($file_onLoad))
                            {
                                    
            unlink($file_onLoad);
                                     echo 
            "<br><br>".$file_onLoad."Silindi <br>";
                            }
                            else
                            {
                                    echo 
            "<script>alert(\"Mantıksal hata oluştu!!\");</script>";
                             }
                        } 





            onAfterInsert

            PHP Code:
            $yol1='C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/_lib/tmp/';
            $yol2='C:/Program Files/NetMake/v7/wwwroot/scriptcase/tmp/';
                
            $filelocation_onBeforeInsert $yol2;
            $ara_onBeforeInsert=(glob($filelocation_onBeforeInsert."sc_*_*.txt"));
            $toplam_onBeforeInsert=count($ara_onBeforeInsert);
            if (
            $toplam_onBeforeInsert=="1")
            {
            $file_onBeforeInsert fopen($ara_onBeforeInsert[0], "r") or exit("Unable to open file!");
            //Output a line of the file until the end is reached
            while(!feof($file_onBeforeInsert))
            {
                
            $satir fgets($file_onBeforeInsert);
                
            //echo $satir . "<br />";
                
            $esr trim($satir);
                
            $ad trim(substr($satir05));
                
            $soyad trim(substr($satir59));
                
            $t2_id = {id};
                
            // SQL statement parameters
                
            $insert_table  't2';      // Table name
                
            $insert_fields = array(   // Field list, add as many as needed
                     
            'ad'  => "'$ad'",
                     
            'soyad'  => "'$soyad'",
                        
            't3_id'  => "'$t2_id'"
                      
            );
            // Insert record
            $insert_sql 'INSERT INTO ' $insert_table
                
            ' ('   implode(', 'array_keys($insert_fields))   . ')'
                
            ' VALUES ('    implode(', 'array_values($insert_fields)) . ')';
            sc_exec_sql($insert_sql);
            }
            $file_onBeforeInsert=$ara_onBeforeInsert[0];
            unlink($file_onBeforeInsert);    
            echo 
            "<script>alert(\"Yükleme başarılı.\");</script>";
            }
                elseif(
            $toplam_onBeforeInsert<>"1")
                    {
                    for ( 
            $say=$say $toplam_onBeforeInsert $say++ )
                        {
                        
            $file_onBeforeInsert=$ara_onBeforeInsert[$say];
                            if(
            file_exists($file_onBeforeInsert))
                            {
                                    
            unlink($file_onBeforeInsert);
                                     echo 
            "<br><br>".$file_onBeforeInsert."Silindi <br>";
                            }
                            else
                            {
                                    echo 
            "<script>alert(\"Mantıksal hata oluştu!!\");</script>";
                             }
                        }
                        echo 
            "<script>alert(\"Aynı anda birden fazla dosya yüklemeye çalıştınız veya yüklenecek dosyayı seçmediniz. Lütfen tekrar deneyiniz.\");</script>";
                    die();
                    } 






            onAfterDelete

            PHP Code:
            $yol1='C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/_lib/tmp/';
            $yol2='C:/Program Files/NetMake/v7/wwwroot/scriptcase/tmp/';

            // SQL statement parameters
            $delete_table  't2';      // Table name
            $delete_where  "t3_id = '".{id}."'"// Where clause

            // Delete record
            $delete_sql 'DELETE FROM ' $delete_table
                
            ' WHERE '      $delete_where;
            sc_exec_sql($delete_sql);
            echo 
            "<script>alert(\"Kayıt silindi.\");</script>";

            $filelocation_onAfterDelete=$yol2;
            $ara_onAfterDelete=(glob($filelocation_onAfterDelete."sc_*_*.txt"));
            $toplam_onAfterDelete=count($ara_onAfterDelete);
                for ( 
            $say=$say $toplam_onAfterDelete $say++ )
                        {
                        
            $file_onAfterDelete=$ara_onAfterDelete[$say];
                            if(
            file_exists($file_onAfterDelete))
                            {
                                    
            unlink($file_onAfterDelete);
                                     echo 
            "<br><br>".$file_onAfterDelete." Silindi <br>";
                            }
                            else
                            {
                                    echo 
            "<br><br>Kayıt Silinmedi !! <br>";
                             }
                        } 

            Comment

            Working...
            X