SunQuest
 
           General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old April 8th, 2003, 04:17 PM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 364 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 26 sec
Reputation Power: 6
fopen, fread, fwrite question

I have 5 files in different directorys. I need to open each of these files and concantonate them into 1 file. the files are comma seperated line by line.

I have a grasp on how to open and read the files, but I am kinda lost on saving the group into 1 file.

TIA
__________________
-- Jason

Reply With Quote
  #2  
Old April 8th, 2003, 06:09 PM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 6
Well, if you are reading the files correctly - you would have each file conetents bound to a scalar. With the scalars, you can write the file as so ->
PHP Code:
 $fp = @fopen'filename.txt''w' ) or exit( 'Need to check directory permissions' );
if ( 
$fp )
{
      @
fwrite$fp$var_one "\n" $var_two "\n" $var_etc ); 
}
@
flose$fp ); 
__________________
~ Joe Penn

We work for free to help make this a valuable resource on the internet. Do you appreciate the help - did we provide help that will help you prosper and help that has contributed to sharpening your current skill set?

Show your appreciation and purchase something from our Amazon Wishlist's - it's simple and a great way to say thank you.




Reply With Quote
  #3  
Old April 8th, 2003, 06:12 PM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 364 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 26 sec
Reputation Power: 6
ok I see,....thanks jpenn

Reply With Quote
  #4  
Old April 8th, 2003, 09:14 PM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 364 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 26 sec
Reputation Power: 6
is there a way using fread that I can skip over the very first line in each file?

Reply With Quote
  #5  
Old April 9th, 2003, 03:48 PM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 6
Well, you can use just file and skip the other filesystem functions. Not nearly as fast as the other filesystem functions, but will do what you need ->
PHP Code:
 $data file'the_text_file.txt' );
$data[0] = ( bool )false;
$data_scalar implode''$data ); 

$data_scalar will hold your data with the first line being removed.

Reply With Quote
  #6  
Old April 9th, 2003, 10:08 PM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 364 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 26 sec
Reputation Power: 6
I am having problems opening the files for reading,.....how would I go about conenction via FTP and retrieving the files that way?

Reply With Quote
  #7  
Old April 9th, 2003, 10:47 PM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 6
Quote:
I am having problems opening the files for reading,.....how would I go about conenction via FTP and retrieving the files that way?

Where are the files stored? Are they on your site or another site?

Reply With Quote
  #8  
Old April 9th, 2003, 10:52 PM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 364 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 26 sec
Reputation Power: 6
they are on my site,.....they are exports from a shopping cart. I would assume since the files are owned by the same user, that I would be able to open them. I can open them and download them fine via FTP.

Reply With Quote
  #9  
Old April 10th, 2003, 01:59 PM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 6
Are you using absolute paths? Example:
PHP Code:
/**************************
This
**************************/
$fp fopen'site.com/files/file.txt''r' );
/**************************
Would Be
**************************/
$fp fopen$_SERVER['DOCUMENT_ROOT'] . '/files/file.txt''r' ); 


Are you getting any errors? Remove the error supression (@) from your functions so the errors will show...

Reply With Quote
  #10  
Old April 10th, 2003, 04:25 PM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 364 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 26 sec
Reputation Power: 6
won't work,...casue the export dir is not in the doc root,...

it would be more like,...

cwd = public_html

dir = ../secure_dir/exports

I think the reason I can't open the public_html dir is not the same owner as the export dir owner.

Reply With Quote
  #11  
Old April 10th, 2003, 06:31 PM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 6
Quote:
won't work,...casue the export dir is not in the doc root,...

Permissions - is this your server or is it a shared host?

Reply With Quote
  #12  
Old April 10th, 2003, 09:11 PM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 364 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 26 sec
Reputation Power: 6
dedicated,....it is ours,....

Reply With Quote
  #13  
Old April 11th, 2003, 10:02 AM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 6
Change the dir permissions so php can access the files. Also, waht errors are being returned?

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > fopen, fread, fwrite question


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |