Boat Drinks  

Go Back   Boat Drinks > General > Computer and Consoles

Reply
 
Thread Tools Display Modes
Old 26-10-2007, 10:47   #1
Desmo
The Last Airbender
 
Desmo's Avatar
 
Join Date: Jun 2006
Location: Pigmopad
Posts: 11,915
Default PHP help - Forward to HTML page?

I've got some PHP script to upload some files (different from the last one I was using), and after it has finished, I'd like to forward on to a different html page.

I've tried using... header("location:http://www.blahblahblah/blah.html");
but that doesn't want to work properly, I think it's the wrong command.

I just need to forward to the html page once the files are uploaded.
Desmo is offline   Reply With Quote
Old 26-10-2007, 10:49   #2
Mark
Screaming Orgasm
 
Join Date: Jul 2006
Location: Newbury
Posts: 15,194
Default

Right command, slightly incorrect header format...

header("Location: http://www.blahblahblah/blah.html");

Mark is offline   Reply With Quote
Old 26-10-2007, 11:03   #3
Desmo
The Last Airbender
 
Desmo's Avatar
 
Join Date: Jun 2006
Location: Pigmopad
Posts: 11,915
Default

When I try that I get this...

Warning: Cannot modify header information - headers already sent by (output started at /home/jmartw00/public_html/crm/afmcustom/uploader.php:12) in /home/jmartw00/public_html/crm/afmcustom/uploader.php on line 198

Line 198 is the header code :/

Here is the page...

Code:
<?php /* Created on: 24/05/2007 */ ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Design by Free CSS Templates
http://www.freecsstemplates.org
Released for free under a Creative Commons Attribution 2.5 License
-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>order</title>
<meta name="Keywords" content="" />
<meta name="Description" content="" />
<link href="http://www.jmartworks.co.uk/default.css" rel="stylesheet" type="text/css" />
</head>
<html>
<body>
<?php
   
   INCLUDE("./dbconn_class.php");
   // instantiate dbconnection 
   $dbConn = new DBConn();
  
   // get all the $_POST values
   $campaign_id = $_POST['campaign_id'];
   $assigned_user_id = $_POST['assigned_user_id'];
   $lead_id =  $_POST['lead_id'];

   // generate unique ID's for the notes ID
   $uid1 = md5(uniqid(rand(), true));
   $uid2 = md5(uniqid(rand(), true));
   $uid3 = md5(uniqid(rand(), true));
   $uid4 = md5(uniqid(rand(), true));
   $uid5 = md5(uniqid(rand(), true));

   // generate the current date to insert into the notes tables
   $current_date = date("Y-m-d H:i:s ", mktime());

 
   // -----------------------------------------
   // File 1

   // Where the file is going to be placed 
   $target_path = "../cache/upload/";

   // SugarCRM requires the filename to be the same as the id in the notes table
   $target_path = $target_path . $uid1; 
   $_FILES['uploadedfile']['tmp_name'];  

  
   if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
//      echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
//       " has been uploaded <br>";

      // original file name
      $FileName = basename( $_FILES['uploadedfile']['name']);

      $sqlString = "INSERT INTO `notes` ( `id` , `date_entered` , `date_modified` , `modified_user_id` , `created_by` , `name` , `filename` , `file_mime_type` , `parent_type` , `parent_id` , `contact_id` , `portal_flag` , `embed_flag` , `description` , `deleted` )
      VALUES ( '$uid1', '$current_date', '$current_date', '1', '1', '$FileName', '$FileName', 'application/msword', 'Leads', '$lead_id', NULL , '0', '0', NULL , '0'); "; 
  
      // commit the entry to the db
      // echo "<br><br>$FileName <br><br> $sqlString <br>";
      $dbConn->query($sqlString);
      $dbConn->commit();
      
   } else{
      echo "There was an error uploading the file, please try again!<br>";
   }

   // -----------------------------------------
   // File 2

   if ( $_FILES['uploadedfile2']['name'] != "" )
   {
      $target_path2 = "../cache/upload/";


      // $target_path2 = $target_path2 . basename( $_FILES['uploadedfile2']['name']); 
      $target_path2 = $target_path2 . $uid2; 

      $_FILES['uploadedfile2']['tmp_name'];  

  
      if(move_uploaded_file($_FILES['uploadedfile2']['tmp_name'], $target_path2)) {
//         echo "The file ".  basename( $_FILES['uploadedfile2']['name']). 
//         " has been uploaded <br>";

         $FileName2 = basename( $_FILES['uploadedfile2']['name']);
   
         $sqlString = "INSERT INTO `notes` ( `id` , `date_entered` , `date_modified` , `modified_user_id` , `created_by` , `name` , `filename` , `file_mime_type` , `parent_type` , `parent_id` , `contact_id` , `portal_flag` , `embed_flag` , `description` , `deleted` )
	        VALUES ( '$uid2', '$current_date', '$current_date', '1', '1', '$FileName2', '$FileName2', 'application/msword', 'Leads', '$lead_id', NULL , '0', '0', NULL , '0'); ";
 
         // echo "<br> $sqlString <br>";
	 $dbConn->query($sqlString);
         $dbConn->commit();

      } else{
         echo "There was an error uploading the file, please try again! <br> ";
      }
  }

   // -----------------------------------------
   // File 3

   if ( $_FILES['uploadedfile3']['name'] != "" )
   {
      $target_path3 = "../cache/upload/";


      // $target_path3 = $target_path3 . basename( $_FILES['uploadedfile3']['name']); 
      $target_path3 = $target_path3 . $uid3; 

      $_FILES['uploadedfile3']['tmp_name'];  

  
      if(move_uploaded_file($_FILES['uploadedfile3']['tmp_name'], $target_path3)) {
//         echo "The file ".  basename( $_FILES['uploadedfile3']['name']). 
//         " has been uploaded <br>";

         $FileName3 = basename( $_FILES['uploadedfile3']['name']);
   
         $sqlString = "INSERT INTO `notes` ( `id` , `date_entered` , `date_modified` , `modified_user_id` , `created_by` , `name` , `filename` , `file_mime_type` , `parent_type` , `parent_id` , `contact_id` , `portal_flag` , `embed_flag` , `description` , `deleted` )
	        VALUES ( '$uid3', '$current_date', '$current_date', '1', '1', '$FileName3', '$FileName3', 'application/msword', 'Leads', '$lead_id', NULL , '0', '0', NULL , '0'); ";
 
         // echo "<br> $sqlString <br>";
	 $dbConn->query($sqlString);
         $dbConn->commit();

      } else{
         echo "There was an error uploading the file, please try again! <br> ";
      }
   }

// -----------------------------------------
   // File 4

   if ( $_FILES['uploadedfile4']['name'] != "" )
   {
      $target_path4 = "../cache/upload/";


      // $target_path4 = $target_path4 . basename( $_FILES['uploadedfile4']['name']); 
      $target_path4 = $target_path4 . $uid4; 

      $_FILES['uploadedfile4']['tmp_name'];  

  
      if(move_uploaded_file($_FILES['uploadedfile4']['tmp_name'], $target_path4)) {
//         echo "The file ".  basename( $_FILES['uploadedfile4']['name']). 
//         " has been uploaded <br>";

         $FileName4 = basename( $_FILES['uploadedfile4']['name']);
   
         $sqlString = "INSERT INTO `notes` ( `id` , `date_entered` , `date_modified` , `modified_user_id` , `created_by` , `name` , `filename` , `file_mime_type` , `parent_type` , `parent_id` , `contact_id` , `portal_flag` , `embed_flag` , `description` , `deleted` )
	        VALUES ( '$uid4', '$current_date', '$current_date', '1', '1', '$FileName4', '$FileName4', 'application/msword', 'Leads', '$lead_id', NULL , '0', '0', NULL , '0'); ";
 
         // echo "<br> $sqlString <br>";
	 $dbConn->query($sqlString);
         $dbConn->commit();

      } else{
         echo "There was an error uploading the file, please try again! <br> ";
      }
  }

// -----------------------------------------
   // File 5

   if ( $_FILES['uploadedfile5']['name'] != "" )
   {
      $target_path5 = "../cache/upload/";


      // $target_path5 = $target_path5 . basename( $_FILES['uploadedfile5']['name']); 
      $target_path5 = $target_path5 . $uid5; 

      $_FILES['uploadedfile5']['tmp_name'];  

  
      if(move_uploaded_file($_FILES['uploadedfile5']['tmp_name'], $target_path5)) {
//         echo "The file ".  basename( $_FILES['uploadedfile5']['name']). 
//         " has been uploaded <br>";

         $FileName5 = basename( $_FILES['uploadedfile5']['name']);
   
         $sqlString = "INSERT INTO `notes` ( `id` , `date_entered` , `date_modified` , `modified_user_id` , `created_by` , `name` , `filename` , `file_mime_type` , `parent_type` , `parent_id` , `contact_id` , `portal_flag` , `embed_flag` , `description` , `deleted` )
	        VALUES ( '$uid5', '$current_date', '$current_date', '1', '1', '$FileName5', '$FileName5', 'application/msword', 'Leads', '$lead_id', NULL , '0', '0', NULL , '0'); ";
 
         // echo "<br> $sqlString <br>";
	 $dbConn->query($sqlString);
         $dbConn->commit();

      } else{
         echo "There was an error uploading the file, please try again! <br> ";
      }
  }
  
  header("Location: http://www.blahblahblah/blah.html");
  
?>
<div id="header">
	<h1>jmartworks.co.uk</h1>
  <h2>because first impressions last</h2>
	<ul>
		<li><a href="index.html" accesskey="1" title="">home</a></li>
		<li><a href="products.html" accesskey="2" title="">products</a></li>
		<li><a href="samples.html" accesskey="3" title="">samples</a></li>
	    <li><a href="orderfiles.php" accesskey="4" title="">order</a></li>
		<li><a href="contact.html" accesskey="5" title="">contact</a></li>
	</ul>
</div>
<div id="content">
	<div id="colOne">
		<h3>what happens now?</h3>
		<div class="bg1">
			<p>Your order has now been sent to us and we shall get back to you shortly.</p>
	  </div>
  </div>
  <div id="colTwo">
    <h3>thank you for your order</h3>
    <div class="bg1">
    <p>We have received your order and will process it shortly. Will will email you at the address supplied confirming the price and artwork level, along with supplying payment details.</p>
    <p>Many thanks, jmartworks.co.uk<p>
  </div>
  </div>
</div>
<div id="footer">
	<p>Copyright (c) 2007 jmartworks.co.uk.</p>
</div>
</body>
</html>
What I effectively want to do is lose all of the html page at the bottom (that was a solution I tried when I couldn't get the forwarding to work) and have the php forward to the thankyou page after if has done it's stuff. Hope that makes sense.
Desmo is offline   Reply With Quote
Old 26-10-2007, 11:06   #4
Mark
Screaming Orgasm
 
Join Date: Jul 2006
Location: Newbury
Posts: 15,194
Default

It's correct. Headers have to come first.

Move this lot...
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Design by Free CSS Templates
http://www.freecsstemplates.org
Released for free under a Creative Commons Attribution 2.5 License
-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>order</title>
<meta name="Keywords" content="" />
<meta name="Description" content="" />
<link href="http://www.jmartworks.co.uk/default.css" rel="stylesheet" type="text/css" />
</head>
<html>
<body>
After the ?> that follows the header().

PS - You should always have some content on a page in case the redirect fails (usually it's just a 'click here' message of some kind).
Mark is offline   Reply With Quote
Old 26-10-2007, 11:07   #5
Jasper
Simple & Red
 
Jasper's Avatar
 
Join Date: Jul 2006
Posts: 535
Default

you need to do the header command before you output any data to the screen. I'm not exactly clear on what you're trying to achieve. Can you shift it all around so that your file uploading logic is done before you output any html? That's how I'd do it, anyway
Jasper is offline   Reply With Quote
Old 26-10-2007, 11:12   #6
Desmo
The Last Airbender
 
Desmo's Avatar
 
Join Date: Jun 2006
Location: Pigmopad
Posts: 11,915
Default

I'd rather lose all the html from that page if I can. I just want it to handle the upload and then if all OK, forward on to the html page I require.

I'll give it a whirl.
Desmo is offline   Reply With Quote
Old 26-10-2007, 11:14   #7
Desmo
The Last Airbender
 
Desmo's Avatar
 
Join Date: Jun 2006
Location: Pigmopad
Posts: 11,915
Default

aha, woot....it's working. Just goes to show what happens if you bodge together other peoples code without knowing what you're doing

Cheers, guys.
Desmo is offline   Reply With Quote
Old 26-10-2007, 11:23   #8
Mark
Screaming Orgasm
 
Join Date: Jul 2006
Location: Newbury
Posts: 15,194
Default

Actually, yeah, for that type of redirect, having no HTML is fine. It's the old meta refresh redirects that need to have HTML as they often fail.
Mark is offline   Reply With Quote
Reply

Thread Tools
Display Modes

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
Forum Jump


All times are GMT +1. The time now is 20:00.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.