Jump to content

Recommended Posts

[code]<?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");
};
?>[/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?
Link to comment
https://forums.phpfreaks.com/topic/4727-header-problems/
Share on other sites

[!--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.
Link to comment
https://forums.phpfreaks.com/topic/4727-header-problems/#findComment-16556
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/4727-header-problems/#findComment-16637
Share on other sites

[!--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
Link to comment
https://forums.phpfreaks.com/topic/4727-header-problems/#findComment-16642
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/4727-header-problems/#findComment-16643
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.