File upload script duel problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
mesz
Forum Contributor
Posts: 216
Joined: Fri May 23, 2003 8:11 am
Location: M/cr

File upload script duel problem

Post by mesz »

(I want you to know I have been trying to fix this myself all day ... I haven't just gone to you guys as a quick fix )
I have a script for uploading MP3s ( my server/host won't allow this filetype...I don't know why...but that is for me to fix :? )
Anyway
The page sporadically and randomlly shows this error:

Code: Select all

Warning: Cannot modify header information - headers already sent by (output started at /home/virtual/site28/fst/var/www/html/phpBB2/displaying.php:14) in /home/virtual/site28/fst/var/www/html/phpBB2/includes/sessions.php on line 297

Warning: Cannot modify header information - headers already sent by (output started at /home/virtual/site28/fst/var/www/html/phpBB2/displaying.php:14) in /home/virtual/site28/fst/var/www/html/phpBB2/includes/sessions.php on line 298
And also everytime the page is visted, a repeat of the information pertaining to the last file uploaded is written to the .dat file.

Can anyone help?

Code: Select all

<?php

define('IN_PHPBB', true);
$phpbb_root_path = '../phpBB2/';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);

//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
//
// End session management
//

if( $userdata['session_logged_in'] )
   {




$imagesdir = "../mp3/updir/";
$fp = fopen('../mp3/news.dat','a+');
$file_name = $_FILES['userfile']['name'];
$file_url  = "../mp3/updir/".$file_name;

if($HTTP_POST_VARS['submit'])
         {
                  $line = date ("F j, Y, g:i a"). "|" . $HTTP_POST_VARS['desc']. "|" . $file_url;

                  $line = str_replace("\r\n","<br>",$line);
                  $line = stripslashes($line);

                  $line .= "\r\n";
                  fwrite($fp, $line);

                  if (isset($_FILES['userfile'])) {
if (!move_uploaded_file($_FILES['userfile']['tmp_name'], $imagesdir . $_FILES['userfile']['name'])) ;
{

				      echo ' ';
				    }
				  } else {
				  echo'';
}

            }
$foom = $fishbaggerss
?>


<FORM ACTION="<?php echo $_SERVER['PHP_SELF']; ?>" METHOD="POST" enctype="multipart/form-data" NAME="mp">
<span class="form2">
Upload MP3 File
</div>
<input type="file" class="button" name="userfile" id="userfile" >
<br>
<span class="form2">
Description
</div>
<TEXTAREA COLS="20" ROWS="5" NAME="desc">
</TEXTAREA>
<br>
<input type="hidden" name="tree" value=$file_url>
<BR>
<INPUT class="button" TYPE="reset" NAME="reset" VALUE="r e s e t">
<INPUT class="button" TYPE="submit" NAME="submit" VALUE="P O S T">
</FORM>

<?php



}


else
       {
               echo('
<form action="/phpBB2/login2.php" method="post">
<input type="text" name="username">
<input type="password" name="password">
<br/>
<input type="submit" class="button" value="login" name="login">
</form>');
       }
?>
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

Make sure there's no whitespace - specfically on line 14!
User avatar
mesz
Forum Contributor
Posts: 216
Joined: Fri May 23, 2003 8:11 am
Location: M/cr

Post by mesz »

That seems to have fixed the error...Cheers. Much appreciated.
But why does the file information keep repeating?
User avatar
mesz
Forum Contributor
Posts: 216
Joined: Fri May 23, 2003 8:11 am
Location: M/cr

Post by mesz »

I just went back to the page...and teh sporadic error message was back...
bugger.
Both problems still there.
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

is it the same line number?
User avatar
mesz
Forum Contributor
Posts: 216
Joined: Fri May 23, 2003 8:11 am
Location: M/cr

Post by mesz »

Yes..the message is now
Warning: Cannot modify header information - headers already sent by (output started at /home/virtual/site28/fst/var/www/html/phpBB2/displaying.php:14) in /home/virtual/site28/fst/var/www/html/phpBB2/includes/sessions.php on line 182

Warning: Cannot modify header information - headers already sent by (output started at /home/virtual/site28/fst/var/www/html/phpBB2/displaying.php:14) in /home/virtual/site28/fst/var/www/html/phpBB2/includes/sessions.php on line 183
User avatar
mesz
Forum Contributor
Posts: 216
Joined: Fri May 23, 2003 8:11 am
Location: M/cr

Post by mesz »

I removed any formatting and that has gotten rid of the header information problem.
But why does the information keep repeating and being written to the .dat file, every time the page is visited?
May 13, 2004, 1:41 pm|Soundhog|../mp3/updir/soundhog_onephatbreeda.mp3
May 13, 2004, 2:03 pm|89|../mp3/updir/_tou2.jpg
May 13, 2004, 2:04 pm|89|../mp3/updir/_tou2.jpg
May 13, 2004, 2:07 pm|89|../mp3/updir/_tou2.jpg
May 13, 2004, 2:07 pm|89|../mp3/updir/_tou2.jpg
May 13, 2004, 2:11 pm|89|../mp3/updir/_tou2.jpg
May 13, 2004, 2:38 pm|tou3|../mp3/updir/_tou3.jpg
May 13, 2004, 2:38 pm|tou3|../mp3/updir/_tou3.jpg
May 13, 2004, 2:38 pm|u|../mp3/updir/_tou2.jpg
May 13, 2004, 2:38 pm|yjnydj|../mp3/updir/_tou2.jpg
May 13, 2004, 2:38 pm|yjnydj|../mp3/updir/_tou2.jpg
May 13, 2004, 2:38 pm|yjnydj|../mp3/updir/_tou2.jpg
May 13, 2004, 2:38 pm|yjnydj|../mp3/updir/_tou2.jpg
May 13, 2004, 2:38 pm|yjnydj|../mp3/updir/_tou2.jpg
May 13, 2004, 3:03 pm|r|../mp3/updir/_tou.jpg
May 13, 2004, 3:03 pm|r|../mp3/updir/_tou.jpg
May 13, 2004, 3:03 pm|r|../mp3/updir/_tou.jpg
May 13, 2004, 3:03 pm|r|../mp3/updir/_tou.jpg
May 13, 2004, 3:03 pm|r|../mp3/updir/_tou.jpg
May 13, 2004, 3:03 pm||../mp3/updir/20posts.htm
May 13, 2004, 3:04 pm||../mp3/updir/20posts.htm
May 14, 2004, 12:54 pm|free MP3 upload test|../mp3/updir/4238.mp3
May 14, 2004, 12:55 pm|wav test|../mp3/updir/1.wav
May 14, 2004, 12:55 pm|wav test|../mp3/updir/1.wav
May 14, 2004, 12:57 pm|wav test|../mp3/updir/1.wav
May 14, 2004, 12:57 pm|wav test|../mp3/updir/1.wav
Also, bizarrely I can upload .wavs but not MP3s...does anyone have any experience with this?
Post Reply