Jump to content

Reading C Data Structures with PHP


Corbie

Recommended Posts

Hi,

 

I'm very new to PHP only days old so if this seems like a silly question I apologzie. I have a file duplication progam I wrote years ago in C on a Unix system. I open up zip files and store CRC info in my own database. It's a great application for php/mysql and I would like to learn php/mysql in the process of moving it over.

 

Can someone tell me how you would read the header (data structure information with all the fields) on a zip file (in this case its the localheader right after the signature), so that all the fields of the structure land nicely in an array in php? I'm attempting to use freads/fseek to  each field and this just can't be right.

 

Doesn't matter what data structure I just need to know the most common method you use to open a file in read blocks of data and unpack them back into a data structure.

 

Many Thanks

 

 

Link to comment
Share on other sites

'm attempting to use freads/fseek to  each field and this just can't be right.

 

What makes you think so?

 

I just need to know the most common method you use to open a file in read blocks of data and unpack them back into a data structure.

 

fread.

Link to comment
Share on other sites

Maybe I a missing something. If I was reading this in C I would do a single fread to a data structure then can immediately use any field with Name.Field. I can also read that entire data stucture with an fread in php but how do you unpack to an array or access each field?

 

Guess that is where I'm stuck.

 

 

Link to comment
Share on other sites

Yeah, I guess I'm a little lost as to exactly what your trying to do. I really only know a little C basics. You can read an entire file into an array using file where each key is a line in the file.

 

Otherwise, you might have some luck with the zip extension.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.