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
Old 11-11-2005, 07:38 AM fgets help
qnc
Skilled Talker

Posts: 74
Trades: 0
fgets help


I cant figure out why this is not working I donot get any error messages just a blank space even $value is not echoning out when enclosed with the fgets()?

I have reduced the code to the problem areas as I see it


PHP Code:
$uploaddir './'// same folder as this file set permission to 0777
  
$pedupload $uploaddir basename($_FILES['pedfile']['name']);
  
$datupload $uploaddir basename($_FILES['datfile']['name']); 
followed by

PHP Code:
foreach ($match as $value
{
 
$handle fopen($pedupload"r");
   if (!
$handle) {
   echo 
"Could not open file $pedupload";
}
else
    {
    
$buffer fgets($handle4096);
    while (!
feof($handle)) {
       echo 
$buffer." ".$value."<br />";
       }
   
fclose($handle);
    } 
where $value is

PHP Code:
$datlines file($datupload);
$datlines_implode implode(" " $datlines);

$regex '/(\w[0-9]+s[0-9]+)/';
preg_match_all($regex $datlines_implode $matched);

$match = Array();
foreach(
$matched[0] as $key=>$value){
        
array_push($match,$value);

Like I said value on its own does work nicely it is just when I try to combine it with the other file.

Any ideas?
qnc is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-13-2005, 05:45 PM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
while (!feof($handle)) {

^ If this fails the first time, you won't see an arror, nor will you see $value.

Try echoing out $pedupload and the using your browser or FTP manually view the file to check its contents.

Are you using the code:
PHP Code:
move_uploaded_file($_FILES['pedfile']['tmp_name'], $pedupload
anywhere to move the file into the right place after upload?
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 11-14-2005, 07:14 AM
qnc
Skilled Talker

Posts: 74
Trades: 0
Thanks for this I am using the following to get the files into arrays or strings I have not decided yet which is better for my purposes.

it does contain

Quote:
Are you using the code:
PHP Code:
move_uploaded_file($_FILES['pedfile']['tmp_name'], $pedupload
anywhere to move the file into the right place after upload?
I have echoed out to make sure that the files is in the right place and has right contents


here is the code in case you spot any mistakes in it.



PHP Code:
if( !isset($_POST['submit'])) { ?>

<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
    <!-- MAX_FILE_SIZE must precede the file input field -->
    <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
    <!-- Name of input element determines name in $_FILES array -->
    Ped file: <input name="pedfile" type="file" /><br />
    Dat file: <input name="datfile" type="file" /><br />
    Smp file: <input name="smpfile" type="file" /><br />
    <input type="submit" name="submit" value="Upload Files" />
</form>


   <?php }

else {

  
$uploaddir './'// same folder as this file set permission to 0777
  
$pedupload $uploaddir basename($_FILES['pedfile']['name']);
  
$datupload $uploaddir basename($_FILES['datfile']['name']);
  
$smpupload $uploaddir basename($_FILES['smpfile']['name']);
  
  echo 
'<pre>';
  if (
move_uploaded_file($_FILES['pedfile']['tmp_name'], $pedupload) &&
      
substr($_FILES['pedfile']['name'],-4) == ".ped") {
    echo 
"Ped file is valid, and was successfully uploaded.\n";
  } else {
    echo 
"Possible file upload attack!\n";
  }
  if (
move_uploaded_file($_FILES['datfile']['tmp_name'], $datupload)&&
      
substr($_FILES['datfile']['name'],-4) == ".dat") {
    echo 
"Dat file is valid, and was successfully uploaded.\n";
  } else {
    echo 
"Possible file upload attack!\n";
  }
  if (
move_uploaded_file($_FILES['smpfile']['tmp_name'], $smpupload)&&
      
substr($_FILES['smpfile']['name'],-4) == ".smp") {
    echo 
"Smp file is valid, and was successfully uploaded.\n";
  } else {
    echo 
"Possible file upload attack!\n";
  }
  
  
// file into arrays
  
$pedlines file($pedupload);
  
$datlines file($datupload);
  
$smplines file($smpupload);
  
  
// files into strings
  
$pedlines_string file_get_contents($pedupload);
  
$datlines_string file_get_contents($datupload);
  
$smplines_string file_get_contents($smpupload);
  
// unlink files after info loaded into array
// ? will it upset the !isset protocol ?

@unlink($_FILES['pedfile']['tmp_name']); 
@
unlink($_FILES['datfile']['tmp_name']); 
@
unlink($_FILES['smpfile']['tmp_name']); 

// check data in files WILL BE REMOVED IN FINAL VERSION!!

$pedlines_implode implode(" " $pedlines);
$datlines_implode implode(" " $datlines);
$smplines_implode implode(" " $smplines);

echo 
"<br /><br /><br /><br />";
echo 
"$pedupload file contains <br /><br /> $pedlines_implode <br /><br /><br />";
echo 
"$datupload file contains <br /><br /> $datlines_implode <br /><br /><br />";
echo 
"$smpupload file contains <br /><br /> $smplines_implode <br /><br /><br />";
}
?>
qnc is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to fgets help
 

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.80474 seconds with 12 queries