Document (File Name) INSERT ERROR ?

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

$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($satir, 0, 5));
	$soyad = trim(substr($satir, 5, 9));

	// 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? :confused:

2 - How can i capture the name of the txt file name created and how? :confused:

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

$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($satir, 0, 5));
	$soyad = trim(substr($satir, 5, 9));

	// 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

if(file_exists($file))
{
    unlink($file);
    echo $file ,"silindi";
}else{
    echo "bu isimde bir dosya yok:".$file;
}

What is your opinion?

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.

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)

Document (File Name)

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

[SIZE=5]onLoad[/SIZE]

$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=0 ; $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>";
	 			}
			}

[SIZE=5]onAfterInsert[/SIZE]


$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($satir, 0, 5));
	$soyad = trim(substr($satir, 5, 9));
	$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=0 ; $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();
		}	

[SIZE=5]onAfterDelete[/SIZE]

$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=0 ; $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>";
	 			}
			}