Jump to content

Recommended Posts

hi people. I have what "should" be a pretty straightforward task to complete, but seeing how i'm not so bright with php i need help...

 

I have mamp installed on my local development machine. I have a database with a table called "products". In that table there's a field called "notes". I have a folder full of text files that were exported from an unrelated program. each one of them is named 1234.txt where "1234" corresponds to the unique value in my key field "serialnumber". There are hundreds of these text files. I want to take the contents of each file and put it in the notes field for the corresponding record. Basically in plain english this is what i want to make a script to do :

 

find a file;

 

strip off the ".txt" from the name;

 

find the record where the filename (minus the .txt) corresponds to a serialnumber value;

 

insert the contents of that text file into the notes field;

 

save the record;

 

keep doing it til you run out of files;

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/267942-automating-some-data-entry/
Share on other sites

For finding files in a directory

   

    opendir or

    glob

 

To get the file contents

 

    file_get_contents

 

To get the id from the filename

    
<?php
    $str = '1234.txt';
    $id = intval($str);   //--> 1234
?>

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.