Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Fwrite to a specific (pre-defined) location
Old 11-28-2005, 03:29 PM Fwrite to a specific (pre-defined) location
Experienced Talker

Posts: 31
Trades: 0
How would I do this? I need it to write on a blank space around...30 or 50 bytes into the file (list.txt). I can't write to a new file and have it read that file because it doesn't know why there's an if statement. Specifically, it's a simple login script using forms.

EDIT: I have seen things for fseek but that doesn't apply to writing...does it?
enerbrat is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-29-2005, 05:08 AM
ibbo's Avatar
Super Spam Talker

Posts: 880
Location: Leeds UK
Trades: 0
You would need to use the fseek method.

Code:
   $fd = fopen('file.dat', 'r');
   // file is now open pointer is set to start of file
   fseek($fd, 512); 
   // Pointer is now midway through the file 
   fseek($fd, -256, SEEK_CUR);
   //Pointer is now a 1/4 into the file
   fseek($fd, -1024, SEEK_END);
   //back to start of file
  
 // check out the following  constants too
  SEEK_CUR
  SEEK_END
  SEEK_SET
Ibbo
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Linux user #349545 :
(GNU/Linux)iD8DBQBAzWjX+MZAIjBWXGURAmflAKCntuBbuKCWenpm XoA7LNydllVQOwCf
ibbo is offline
Reply With Quote
View Public Profile Visit ibbo's homepage!
 
Old 11-29-2005, 05:27 AM
ibbo's Avatar
Super Spam Talker

Posts: 880
Location: Leeds UK
Trades: 0
$byte = fread($fd, 1);

use that after a seek to get the current byte.

Ibbo
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Linux user #349545 :
(GNU/Linux)iD8DBQBAzWjX+MZAIjBWXGURAmflAKCntuBbuKCWenpm XoA7LNydllVQOwCf
ibbo is offline
Reply With Quote
View Public Profile Visit ibbo's homepage!
 
Old 11-29-2005, 04:08 PM
Experienced Talker

Posts: 31
Trades: 0
I take it I'm doing it wrong but here's the code:

PHP Code:
$filename "pass.php";
$fd fopen ($filename'r') or die ('$filename not found');
fseek($fd512);
fseek($fd, -413SEEK_CUR);
fread($fd1);
fwrite ($fd$full);
fclose($fd); 
enerbrat is offline
Reply With Quote
View Public Profile
 
Old 11-30-2005, 05:30 AM
ibbo's Avatar
Super Spam Talker

Posts: 880
Location: Leeds UK
Trades: 0
First off your opening the file for reading only 'r'. Change that to 'w' or even 'r+'.

PHP Code:
$full "now then";
$filename "pass.php";

$fd fopen ($filename'w') or die ('$filename not found');
fseek($fd512);
fseek($fd, -413SEEK_CUR);
fread($fd1);

if(
fwrite ($fd$full) == NULL){
  
var_dump("Failed fwrite");
}
fclose($fd); 
open up pass.php and see the text.

Ibbo
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Linux user #349545 :
(GNU/Linux)iD8DBQBAzWjX+MZAIjBWXGURAmflAKCntuBbuKCWenpm XoA7LNydllVQOwCf

Last edited by ibbo; 11-30-2005 at 05:40 AM..
ibbo is offline
Reply With Quote
View Public Profile Visit ibbo's homepage!
 
Old 12-01-2005, 03:38 PM
Experienced Talker

Posts: 31
Trades: 0
Ah, okay. Yea I completely forgot about changing the write mode. Thanks.
enerbrat is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Fwrite to a specific (pre-defined) location
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.22415 seconds with 12 queries