You are here: Re: need some help with this solution... « All PHP « IT news, forums, messages
Re: need some help with this solution...

Posted by gerg on 01/30/06 20:18

J.O. Aho wrote:
> Greg wrote:
>
>>I have a new client (an ag pesticide sprayer) and he has a piece of
>>software that generates reports about all the chemicals that he sprays
>>on any particular day. The reports are in .txt format. As an end
>>result I need to take that .txt file and and
>>
>>a) create an upload script for the .txt file
>
>
> You could use something like the script
> http://www.hotscripts.com/Detailed/31396.html
>
> Just searching on google for "php simple upload script" generates around
> 2,670,000 hits, so there are many to find and use.
>
>
>
>>b) open and read the text file into an array ( implode() ?)
>
>
> explode()
> otherwise you can read one line at the time and insert the things to the
> database with fgets()
>
>
>
>>c) insert the text of that array into the database.
>
>
> The basics works like:
> mysql_query("INSER INTO table VALUE('$text')");
>
>
>
>>d) save the .txt file to another folder on the server to act as a back
>>up should anything ever happen to the database.
>
>
> Look at the upload script, and I suggest you would in this case rename the
> file to have an unique name based on time/date, in case the customer happens
> to upload more than once a day, not sure all are "valid" versions.
>
>
>
>>e) create a user end that will allow clients to view which pesticides
>>have been sprayed on which day, etc...
>
>
> Thats quite easy, you make a SQL query and then loop the results
>
> $result=mysql_query("SELECT * FROM table");
> while($row=mysql_fetch_array($result)) {
> echo $row[0]."<br>\n";
> }
>
>
>
>>f) as a side note, if someone could explain a little about cron jobs, as
>>i would want the database backed up nightly and have the db file emailed
>>to my inbox. I've never dabbled with cron jobs so I don't know much
>>about them.
>
>
> This gives you all the info you need:
> man 5 contab
>
> [minute] [hour] [day of month] [month] [day of week] [run as who] [what to do]
>
> The five first can have a '*' which tells that it don't matter what time.
> for weekday, 1 is Monday, 0 and 7 is Sunday.
>
>
>
>>Does this sound like the best way to do this? I was just going to store
>>the .txt file in the database, but figured it may be to processor
>>intensive when it comes to searching ALL the files which will grow to a
>>huge amount over time. I would really appreciate any feedback on the
>>above logic. Thanks in advance.
>
>
> If it's in a database, it's easier to search for data and if you make backups
> the txt files aren't that important, but of course the database will grow with
> time as the storage directory will and you can delete as easily from the
> database as from the storage directory if you would need to save space.
>
> The only real reason I can see to save the txt files, is to ensure that the
> data has been inserted into the database, but this don't have to be more than
> a short time storage.
>
>
> //Aho

This is a wealth of info. Thanks so much for your response. If I may
ponder a few more ideas:

so, i'll upload the file ( I can write a scipt or find one to use )

Open said file with fopen() ( Where does fgets() come into play. Seems
to only return a lenght? I wasn't getting much from php.net. )

so I will need to somehow transfer the text of the .txt file into a
variable. Is this what the explode() is used for? Once I get the array
I think i'll be good. I was under the understanding that explode will
create an array out of every new line. Would that look something like this:

$myarray = explode("/n",$my_text_from_uploaded_file);

so that every new line in the document would then be turned into an array?

When I run the query into the database I just want the text to be input
in the database just like it is on the text document. Do I even need an
array for this? Or is there a simpler function that will just copy the
text to a variable that I can dump in the database?

Let me know where you live and I'll talk you to dinner and drinks for
helping me wiht this! :)

Thanks again,

Greg

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация