lpxxfaintxx Posted March 12, 2006 Share Posted March 12, 2006 [code]<?phpinclude '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");};?>[/code][!--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? Quote Link to comment https://forums.phpfreaks.com/topic/4727-header-problems/ Share on other sites More sharing options...
AndyB Posted March 12, 2006 Share Posted March 12, 2006 [!--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. Quote Link to comment https://forums.phpfreaks.com/topic/4727-header-problems/#findComment-16556 Share on other sites More sharing options...
lpxxfaintxx Posted March 12, 2006 Author Share Posted March 12, 2006 All db.php is doing is connecting to the database. Thats intefering with the script? Quote Link to comment https://forums.phpfreaks.com/topic/4727-header-problems/#findComment-16635 Share on other sites More sharing options...
AndyB Posted March 12, 2006 Share Posted March 12, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/4727-header-problems/#findComment-16637 Share on other sites More sharing options...
saiko Posted March 12, 2006 Share Posted March 12, 2006 [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]<?phpinclude '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--]<?phpob_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 Quote Link to comment https://forums.phpfreaks.com/topic/4727-header-problems/#findComment-16642 Share on other sites More sharing options...
lpxxfaintxx Posted March 12, 2006 Author Share Posted March 12, 2006 Thanks, I'll go check it out. edit: It works great! Thanks for your time and support.[quote]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.[/quote]Yes, there is a seperate form called upload.html. Quote Link to comment https://forums.phpfreaks.com/topic/4727-header-problems/#findComment-16643 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.