New on LowEndTalk? Please Register and read our Community Rules.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
Anyone know how to convert .c part of code into .php ?
This is the code: https://pastebin.com/raw/MDihpbvq
It goes thru folders and update file called dirlog
I only need to convert the part where it writes directory names info file called dirlog
The writing part i think is this:
log.status = 0;
log.uptime = (time_t) st.st_mtime;
log.uploader = (unsigned short int) st.st_uid;
log.group = (unsigned short int) st.st_gid;
strncpy (log.dirname, temppath, sizeof(log.dirname) - 1);
bytes = 0ULL;
files = 0;
get_dir_size(temppath, &files, &bytes);
log.files = files;
log.bytes = bytes;
update_log(log);
Anyone know how to convert it? Thx much!
Comments
Read this http://php.net/manual/en/function.fwrite.php and http://php.net/manual/en/function.mkdir.php
I know both And a lot more, the problem is it write into log file as this and i cant understand from that .c file how to do it in php:
nano dirlog
It's some sort of folder scanner and logger? Why are you going in such hard way to understand .c and convert it to PHP... Maybe this will be helpful for you:
https://stackoverflow.com/questions/608450/using-scandir-to-find-folders-in-a-directory-php
yep it scan and write folder names with date and size into dirlog file
the problem is it writes it in some special format, see m above reply when i did nano it show some weir characters before and after dir folder, and i need to write it in exact format
Sounds like an X-Y problem…
You would find it easier to compile that C code into a library and call it from PHP through a PHP-C bridge.
update_log searches the logfile for a matching struct dirlog entry with the same directory name, and overwrites it. If no match is found, it appends a new entry to the end of the file.
The writes to the logfile are in binary format, so you would need to look up struct dirlog to understand the exact sequence of bits. It should be defined in "glconf.h".
I'm closing this thread because it is offtopic, is not a good question, is not helpful, and the stars do not align, so therefore you have grossly violated site policy and you are a bad person.
Oh...sorry, for a moment I thought I was on StackExchange instead of someplace helpful.
C can read/write binary files with a 'b' attribute so it makes no sense when you view the file in notepad. You should convert it into ascii file using something like Notepad++ or do it yourself in C.
if you need binary compatibility, use the pack function to convert php types to their binary representation.
http://php.net/manual/en/function.pack.php
Just execute the compiled c program it via exec on php using appropriate arguments.