Jump to content


Photo

Header Problems


  • Please log in to reply
5 replies to this topic

#1 lpxxfaintxx

lpxxfaintxx
  • Members
  • PipPipPip
  • Advanced Member
  • 181 posts

Posted 12 March 2006 - 02:35 AM

<?php
include 'db.php';
$username = $userdata['user_name'];
$filename = str_replace(' ', '', $_FILES['userfile']['name']);
$tblw = strlen($filename);
$ext = substr($filename, $tblw-3, $tblw);
$exts = array("png", "gif", "jpg");
if ($ext == 'png' OR $ext == 'gif' OR $ext == 'jpg') {
   $idq = mysql_query("SELECT `id` FROM `files` ORDER BY `id` DESC LIMIT 1");
   $ida = mysql_fetch_assoc($idq);
   $id = $ida['id'] + 1;
   $uploaddir = '/wamp/www/aimphotogallery/upload/';
   $path = '/wamp/www/aimphotogallery/upload/'.$id. '.'.$ext;
   $uploadfile = $uploaddir . $id . "." . $ext;
   move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile);
   mysql_query("INSERT INTO `files` (`id`,`path`,`owner`) VALUES('$id','$path','$username')");
   header("Location: http://www.phpfreaks.com");
};
?>

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\aimphotogallery\db.php:9) in C:\wamp\www\aimphotogallery\upload.php on line 17[/quote]

I know it has to be before all the code, but then the rest of the file won't be executed. Is there any ways around thing?

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 12 March 2006 - 02:57 AM

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]I know it has to be before all the code, but then the rest of the file won't be executed. Is there any ways around thing?[/quote]
If that's the entire script, then something, somewhere in db.php is outputting to the browser. The solution is going to be to rewrite/re-order/restructure the code so that in the case when the header is called, nothing else has happened in terms of browser output. Looking at the script, it's clear there's likely to be quite a bit going on elsewhere. Maybe we need to see all (xxx out any passwords, etc.) parts that make up the whole thing.
Legend has it that reading the manual never killed anyone.
My site

#3 lpxxfaintxx

lpxxfaintxx
  • Members
  • PipPipPip
  • Advanced Member
  • 181 posts

Posted 12 March 2006 - 12:04 PM

All db.php is doing is connecting to the database. Thats intefering with the script?

#4 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 12 March 2006 - 12:20 PM

Wait a minute. There's obviously a form involved in the script to provide the information about the uploaded file as well as the file itself. If all db.php does is connect to the database, then isn't there code somewhere with the upload form? The code you posted can't work sensibly without having values for what you're trying to put in the database, etc., that's why I think what's posted isn't all the scripting involved ... and something, somewhere, really is sending output to the browser.
Legend has it that reading the manual never killed anyone.
My site

#5 saiko

saiko
  • Members
  • PipPipPip
  • Advanced Member
  • 37 posts

Posted 12 March 2006 - 12:38 PM

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]<?php
include 'db.php';
$username = $userdata['user_name'];
$filename = str_replace(' ', '', $_FILES['userfile']['name']);
$tblw = strlen($filename);
$ext = substr($filename, $tblw-3, $tblw);
$exts = array("png", "gif", "jpg");
if ($ext == 'png' OR $ext == 'gif' OR $ext == 'jpg') {
$idq = mysql_query("SELECT `id` FROM `files` ORDER BY `id` DESC LIMIT 1");
$ida = mysql_fetch_assoc($idq);
$id = $ida['id'] + 1;
$uploaddir = '/wamp/www/aimphotogallery/upload/';
$path = '/wamp/www/aimphotogallery/upload/'.$id. '.'.$ext;
$uploadfile = $uploaddir . $id . "." . $ext;
move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile);
mysql_query("INSERT INTO `files` (`id`,`path`,`owner`) VALUES('$id','$path','$username')");
header("Location: [a href=\"http://www.phpfreaks.com");\" target=\"_blank\"]http://www.phpfreaks.com");[/a]
};
?>[/quote]


change to


[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]<?php
ob_start();
include 'db.php';
$username = $userdata['user_name'];
$filename = str_replace(' ', '', $_FILES['userfile']['name']);
$tblw = strlen($filename);
$ext = substr($filename, $tblw-3, $tblw);
$exts = array("png", "gif", "jpg");
if ($ext == 'png' OR $ext == 'gif' OR $ext == 'jpg') {
$idq = mysql_query("SELECT `id` FROM `files` ORDER BY `id` DESC LIMIT 1");
$ida = mysql_fetch_assoc($idq);
$id = $ida['id'] + 1;
$uploaddir = '/wamp/www/aimphotogallery/upload/';
$path = '/wamp/www/aimphotogallery/upload/'.$id. '.'.$ext;
$uploadfile = $uploaddir . $id . "." . $ext;
move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile);
mysql_query("INSERT INTO `files` (`id`,`path`,`owner`) VALUES('$id','$path','$username')");
header("Location: [a href=\"http://www.phpfreaks.com");\" target=\"_blank\"]http://www.phpfreaks.com");[/a]
};
ob_end_flush();
?>[/quote]

shuld work i hope

#6 lpxxfaintxx

lpxxfaintxx
  • Members
  • PipPipPip
  • Advanced Member
  • 181 posts

Posted 12 March 2006 - 12:40 PM

Thanks, I'll go check it out. edit: It works great! Thanks for your time and support.

Wait a minute. There's obviously a form involved in the script to provide the information about the uploaded file as well as the file itself. If all db.php does is connect to the database, then isn't there code somewhere with the upload form? The code you posted can't work sensibly without having values for what you're trying to put in the database, etc., that's why I think what's posted isn't all the scripting involved ... and something, somewhere, really is sending output to the browser.


Yes, there is a seperate form called upload.html.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users