-2

I wanted to create a .dat file on my server cpanel and wanted that file to be uploaded in "data_files" folder on my server. Here is the code that i created,

<?php

$a = "H";
$b = "Z01284001";
$c = "             ";
$e = "20181122";
$d = "                                        ";
$f = "E72402";
$k = "                 ";
$g = "Sabah Care Specialist CliLot 9, Lintas Jaya Uptown";
$l = "                                                        ";
$h = "PRN";
$m = "                                                     ";

$n = "D";
$o = "EPFLX20";
$p = "             ";
$q = "S";
$r = "                          ";
$s = "000002780000020000000000000";
$t = "                                                                                                                                                                                  ";

$u = "T";
$v = "                                                                                                                                                                                                                                                               ";

$file = fopen("/abc/ced/dat_files/testing.dat","w");
fwrite($file,"$a$b$c$e$d$f$k$g$l$h$m\n$n$o$p$q$r$s$t\n$u$v");
fclose($file);
echo "File created successfully!";

?>

Please help me out.

Akshaya
  • 37
  • 1
  • 8
  • 2
    Possible duplicate of [Create a folder if it doesn't already exist](https://stackoverflow.com/questions/2303372/create-a-folder-if-it-doesnt-already-exist) – Kaddath Dec 04 '18 at 08:28
  • Please do not edit your post so that it changes the requirements as to make completely invalid existing answers and comments. If you think you asked the wrong question, you should delete this one and open a new one. – Kaddath Dec 04 '18 at 10:49

1 Answers1

0
if (!is_dir("dat_files")) {
  mkdir("dat_files");
}

Assuming your current user has write rights on the current folder.

  • but problem is when i use fopen("/abc/ced/data_files/test.dat","w") I am not getting that file in data_files folder on server please help me out – Akshaya Dec 04 '18 at 10:27
  • @Akshaya in your code you wrote **dat_files** not **data_files** . – Aldo Tripiciano Dec 05 '18 at 12:50
  • @AldoTripiciano can you help me https://stackoverflow.com/questions/62169939/how-to-export-file-in-dat-format-using-php – Siva Jun 03 '20 at 10:01