Jump to content

so much trouble with this code!


jesushax

Recommended Posts

been trying to fix thsi for weeks now, everytime i do it goes tits up again

 

Please HELP!! its th eonly that doesnt work on my site now...

 

Thanks

 

heres the error(s)

Warning: Invalid argument supplied for foreach() in /home/fhlinux153/c/cwservicesltd.co.uk/user/htdocs/admin/portfolio/edit_project.php on line 156

 

Warning: Cannot modify header information - headers already sent by (output started at /home/fhlinux153/c/cwservicesltd.co.uk/user/htdocs/admin/portfolio/edit_project.php:19) in /home/fhlinux153/c/cwservicesltd.co.uk/user/htdocs/admin/portfolio/edit_project.php on line 176

heres the code...

 

<?php
include($_SERVER['DOCUMENT_ROOT'] . '/includes/header.php');
include($_SERVER['DOCUMENT_ROOT'] . '/includes/admin_access.inc');
?>
<div id="subs-container">
<div id="subs">
<div id="subs-admin-text">
<div class="padding">
<ul>
<li class="menu">Portfolio Menu:</li>
<li class="menu"><a href="/admin/portfolio/add_project.php">Add</a></li>
<li class="menu"><a href="/admin/portfolio/index.php">View/Edit</a></li>
<li class="menu"><a href="/admin/portfolio/current_projects.php">Current Projects</a></li>
</ul>
</div>
</div>
</div>
</div>
<div id="lower-container">
<div id="backlinks"><?php include($_SERVER['DOCUMENT_ROOT'] . '/includes/backlinks.php'); ?></div>
<div id="content">
<div class="padding">
<?php
function searchForThis($data, $search){
if (strstr($data, $search)){
	echo 'checked="checked"';}
}
$absolute_path = $_SERVER['DOCUMENT_ROOT'] . "/portfolio/images/";//Absolute path to where files are uploaded
$thumb_path = $_SERVER['DOCUMENT_ROOT'] . "/portfolio/images/thumbs/";   //Absolute path to where thumbs are to be stored if you want this
$size_limit = "yes";                                          //do you want a size limit yes or no.
$limit_size = "4000000";                                       //How big do you want size limit to be in bytes
$limit_ext = "yes";                                           //do you want to limit the extensions of files uploaded
$ext_count = "4";                                             //total number of extensions in array below
$extensions = array(".jpg", ".jpeg", ".png", ".gif");         //List extensions you want files uploaded to be

function resampleimage($maxsize, $sourcefile, $destination, $imgcomp=0){
// SET THE IMAGE COMPRESSION
$g_imgcomp=100-$imgcomp;
  // CHECK TO SEE IF THE IMAGE EXISTS FIRST
  if(file_exists($sourcefile)){
  // FIRST WE GET THE CURRENT IMAGE SIZE
  $g_is=getimagesize($sourcefile);
    /********* CALCULATE THE WIDTH AND THE HEIGHT ***************/
    // CHECK TO SEE IF THE WIDTH AND HEIGHT ARE ALREADY SMALLER THAN THE MAX SIZE
    if($g_is[0] <= $maxsize && $g_is[1] <= $maxsize){
    // LEAVE WIDTH AND HEIGHT ALONE IF IMAGE IS SMALLER THAN MAXSIZE
    $new_width=$g_is[0];
    $new_height=$g_is[1];
    } else {
    // GET VALUE TO CALCULATE WIDTH AND HEIGHT
    $w_adjust = ($maxsize / $g_is[0]);
    $h_adjust = ($maxsize / $g_is[1]);
      // CHECK TO WHICH DIMENSION REQUIRES THE SMALLER ADJUSTMENT
      if($w_adjust <= $h_adjust){
      // CALCULATE WIDTH AND HEIGHT IF THE WIDTH VALUE IS SMALLER
      $new_width=($g_is[0]*$w_adjust);
      $new_height=($g_is[1]*$w_adjust);
      } else {
      // CALCULATE WIDTH AND HEIGHT IF THE HEIGHT VALUE IS SMALLER
      $new_width=($g_is[0]*$h_adjust);
      $new_height=($g_is[1]*$h_adjust);
      }
    }
  //SEARCHES IMAGE NAME STRING TO SELECT EXTENSION (EVERYTHING AFTER THE LAST "." )
$image_type = strrchr($sourcefile, ".");

//SWITCHES THE IMAGE CREATE FUNCTION BASED ON FILE EXTENSION
switch($image_type) {
	case '.jpg':
		$img_src = imagecreatefromjpeg($sourcefile);
		break;
	case '.jpeg':
		$img_src = imagecreatefromjpeg($sourcefile);
		break;
	case '.png':
		$img_src = imagecreatefrompng($sourcefile);
		break;
	case '.gif':
		$img_src = imagecreatefromgif($sourcefile);
		break;
	default:
		echo("Error Invalid Image Type");
		die;
		break;
}
  // CREATE THE TRUE COLOR IMAGE WITH NE WIDTH AND HEIGHT
  $img_dst=imagecreatetruecolor($new_width,$new_height);
  // RESAMPLE THE IMAGE TO NEW WIDTH AND HEIGHT
  imagecopyresampled($img_dst, $img_src, 0, 0, 0, 0, $new_width, $new_height, $g_is[0], $g_is[1]);
  // OUTPUT THE IMAGE AS A JPEG.
  // THIS CAN BE CHANGED IF YOU WANT TRANSPARENCY OR PREFER ANOTHER FORMAT. MAKE SURE YOU CHANGE HEADER ABOVE.
  imagejpeg($img_dst, $destination, 100);
  // DESTROY THE NEW IMAGE
  imagedestroy($img_dst);
  return true;
  } else {
  return false;
  }
}

switch(@$_GET["action"]) {
Case "edit":

$PortID = $_POST["txtID"];
$Type = $_POST["SelType"];
$Company = $_POST["txtCompany"];
$Name = $_POST["txtName"];
$URL = $_POST["txtUrl"];
$Location = $_POST["txtLocation"];
$Logo = $_FILES['pictures']['name'][0];
$Image1 = $_FILES['pictures']['name'][1];
$Image2 = $_FILES['pictures']['name'][2];
$Image3 = $_FILES['pictures']['name'][3];
$Case = $_POST["txtCase"];
$Result = $_POST["txtResult"];
$Brief = $_POST["txtBrief"];
$CommentsTitle = $_POST["txtCommentsTitle"];
$Comments = $_POST["txtComments"];
$Date = date("yyyy-mm-dd");

if (!empty($_POST["chkXHTML"])) {
$Services = ":".$_POST["chkXHTML"].":";}
if (!empty($_POST["chkWebDesign"])) {
$Services = $Services.":".$_POST["chkWebDesign"].":";}
if (!empty($_POST["chkCMS"])) {
$Services = $Services.":".$_POST["chkCMS"].":";}
if (!empty($_POST["chkOnlineDB"])) {
$Services = $Services.":".$_POST["chkOnlineDB"].":";}
if (!empty($_POST["chkPDF"])) {
$Services = $Services.":".$_POST["chkPDF"].":";}
if (!empty($_POST["chkMembership"])) {
$Services = $Services.":".$_POST["chkMembership"].":";}
if (!empty($_POST["chkBranding"])) {
$Services = $Services.":".$_POST["chkBranding"].":";}

$SQL = "UPDATE tblPortfolio Set PortType='$Type', ClientCompany='$Company', ClientName='$Name', ClientUrl='$URL', ClientLocation='$Location', ";

if (!empty($Logo)) {
$SQL = $SQL."ClientLogo='$Logo', ";
}
if (!empty($PortImage1)) {
$SQL = $SQL."PortImage1='$Image1', ";
}
if (!empty($PortImage2)) {
$SQL = $SQL."PortImage2='$Image2', ";
}
if (!empty($PortImage3)) {
$SQL = $SQL."PortImage3='$Image3', ";
}

$SQL = $SQL."ClientCase='$Case', ClientResult='$Result', ClientBrief='$Brief', ClientServices='$Services',  ClientCommentsTitle='$CommentsTitle', ClientComments='$Comments', PortDateEdited='$Date' WHERE PortID='$PortID' ";

mysql_query($SQL) or die(mysql_error());

$error=0;
  foreach ($_FILES["pictures"]["error"] as $key => $error) {
  $file_name =  $_FILES["pictures"]['name'][$error]; // can call this anything you like this will take the original name
  $file =  $_FILES["pictures"]['tmp_name'][$error];
  $file_size = $_FILES["pictures"]['size'][$error];
      if (($size_limit == "yes") && ($limit_size < $file_size)) {
        header("Location: /admin/portfolio/edit_project.php?error=filesize");
        } else {
        $ext = strrchr($file_name,'.');
          if (($limit_ext == "yes") && (!in_array($ext,$extensions))) {
        header("Location: /admin/portfolio/edit_project.php?error=filetype");
          }else{
          $j = $error + 1;
          // first move the file to
          move_uploaded_file($file, $absolute_path.$file_name);
          // Save full size image with max width/height
          resampleimage("175", $absolute_path.$file_name, $absolute_path.$file_name, 0); 
        }
        }
  $error++;
  }
    header("Location: /admin/portfolio/index.php");
break;
default:

function showimagesize($im){
    $Imagesize = getimagesize($_SERVER['DOCUMENT_ROOT']."/portfolio/images/".$im."");
    $width = $Imagesize[0] + 40; 
    $height = $Imagesize[1] + 40;
    echo   "<a href=\"/portfolio/images/$im\" onclick=\"NewWindow(this.href,'name','$width','$height','yes');return false\">$im</a>";
}

$extens = '';

        if (($extensions == "") or ($extensions == " ") or ($ext_count == "0") or ($ext_count == "") or ($limit_ext != "yes") or ($limit_ext == "")) {
           $extens = "any extension";
        } else {
        $ext_count2 = $ext_count+1;
        for($counter=0; $counter<$ext_count; $counter++) {
            $extens .= "  $extensions[$counter]";
        }
        }
        if (($limit_size == "") or ($size_limit != "yes")) {
            $limit_size = "any size";
        } else {
            $limit_size .= " bytes";
            $mb_size = ($limit_size/1000000);
        }
        $pichead = "<ul style=\"color:#FF0000; font-size:10px;\"><li style=\"display:inline; padding-right:10px;\">File extension must be $extens |</li>";
        $pichead .="<li style=\"display:inline; padding-right:10px;\">Maximum file size is $limit_size ($mb_size MB) |</li>
        			<li style=\"display:inline; padding-right:10px;\">No spaces in the filename</li></ul>";

$ID = $_GET["ID"];

$PortSQL = mysql_query("SELECT * FROM tblPortfolio WHERE PortID='$ID' ") or die(mysql_error());

while ($rsEdit = mysql_fetch_array($PortSQL)) {
?>
<script type="text/javascript">
bkLib.onDomLoaded(function() {
new nicEditor({xhtml:true}).panelInstance('txtCase');	
new nicEditor({xhtml:true}).panelInstance('txtResult');	
new nicEditor({xhtml:true}).panelInstance('txtBrief');	
new nicEditor({xhtml:true}).panelInstance('txtComments');	
});
</script>
<h3>Edit Project</h3>
<form action="<?=$_SERVER['PHP_SELF']?>?action=edit" method="post" enctype="multipart/form-data" />
<input name="txtID" type="hidden"  value="<?php echo $rsEdit["PortID"]; ?>" />
<table width="100%">
<tr>
  <td><strong>Project Type:</strong></td>
  <td colspan="4"><select name="SelType">
  <option><?php echo $rsEdit["PortType"]; ?></option>
    <option>Marketing</option>
    <option>Technical</option>
    <option>Web Design</option>
  </select>  </td>
</tr>
<tr>
  <td><strong>Company Name:</strong></td>
  <td colspan="4"><input name="txtCompany" type="text" size="50" value="<?php echo $rsEdit["ClientCompany"]; ?>" /></td>
</tr>
<tr>
  <td><strong>Client Name</strong></td>
  <td colspan="4"><input name="txtName" type="text" id="txtName" size="50" value="<?php echo $rsEdit["ClientName"]; ?>" /></td>
</tr>


<tr>
  <td><strong>Client Location</strong></td>
  <td colspan="4"><input name="txtLocation" type="text" id="txtLocation" size="50" value="<?php echo $rsEdit["ClientLocation"]; ?>" /></td>
</tr>
<tr>
  <td><strong>Url:</strong></td>
  <td colspan="4"><input name="txtUrl" type="text" size="70" value="<?php echo $rsEdit["ClientUrl"]; ?>" /></td>
</tr>
<tr>
  <td><strong>Client Logo:</strong></td>
  <td><input type="file" name="pictures[]" size="50" /></td>
  <td>Current Logo:</td>
  <td><?php showimagesize($rsEdit["ClientLogo"]); ?></td>
</tr>
<tr><td><strong>Image 1:</strong></td><td><input type="file" name="pictures[]" size="50" /></td>
  <td>Current Image 1</td>
  <td><?php showimagesize($rsEdit["PortImage1"]); ?></td>
</tr>
<tr><td><strong>Image 2:</strong></td><td><input type="file" name="pictures[]" size="50" /></td>
  <td>Current Image 2</td>
  <td><?php showimagesize($rsEdit["PortImage2"]); ?></td>
</tr>
<tr><td><strong>Image 3:</strong></td><td><input type="file" name="pictures[]" size="50" /></td>
  <td>Current Image 3</td>
  <td><?php showimagesize($rsEdit["PortImage3"]); ?></td>
</tr>
<tr>
  <td colspan="5"><? echo $pichead; ?></td>
</tr>
<tr>
  <td colspan="5"><strong>Client Brief / About the Client:</strong></td>
</tr>
<tr>
  <td colspan="5"><textarea name="txtBrief" style="width:550px; height:175px;"><?php echo $rsEdit["ClientBrief"]; ?></textarea></td>
<tr>
<tr>
  <td colspan="5"><strong>What the client wanted:</strong></td>
</tr>
<tr>
  <td colspan="5"><textarea name="txtCase" style="width:550px; height:175px;"><?php echo $rsEdit["ClientCase"]; ?></textarea></td>
<tr>
  <td colspan="5"><strong>Case result:</strong></td>
</tr>
<tr>
  <td colspan="5"><textarea name="txtResult" style="width:550px; height:175px;"><?php echo $rsEdit["ClientResult"]; ?></textarea></td>
<tr>
  <td colspan="5"><strong>Client Services</strong></td>
<tr>
  <td colspan="5">
<?php $data = $rsEdit["ClientServices"]; ?>
  <table width="50%" border="0">
    <tr>
      <td>XHTML/CSS Standards Compliant</td>
      <td><input type="checkbox" name="chkXHTML" value="XHTML/CSS Standards Compliant" class="blank"
       <?php $search = "XHTML/CSS Standards Compliant"; searchForThis($data, $search);?> /></td>
      <td>Form to PDF/Email</td>
      <td><input type="checkbox" name="chkPDF" value="Form to PDF/Email" class="blank"
      <?php $search = "Form to PDF/Email"; searchForThis($data, $search);?>  /></td>
    </tr>
    <tr>
      <td>Webpage Design</td>
      <td><input type="checkbox" name="chkWebDesign" value="Webpage Design" class="blank" id="chkWebDesign"
      <?php $search = "Webpage Design"; searchForThis($data, $search);?> /></td>
      <td>Membership System</td>
      <td><input type="checkbox" name="chkMembership" value="Membership System" class="blank"
      <?php $search = "Membership System"; searchForThis($data, $search);?> /></td>
    </tr>
    <tr>
      <td>Content Management System</td>
      <td><input type="checkbox" name="chkCMS" value="Content Mangement System" class="blank"
      <?php $search = "Content Mangement System"; searchForThis($data, $search);?> /></td>
      <td>Corporate Branding</td>
      <td><input type="checkbox" name="chkBranding" value="Corporate Branding" class="blank"
      <?php $search = "Corporate Branding"; searchForThis($data, $search);?> /></td>
    </tr>
    <tr>
      <td>Online Database</td>
      <td><input type="checkbox" name="chkOnlineDB" value="Online Database" class="blank"
      <?php $search = "Online Database"; searchForThis($data, $search);?> /></td>
      <td> </td>
      <td> </td>
    </tr>
  </table>  </td>
</tr>
<tr>
  <td> </td>
  <td colspan="4"> </td>
</tr>
<tr>
  <td><strong>Client Comments:</strong></td>
  <td colspan="4"><input name="txtCommentsTitle" type="text" size="50" value="<?php echo $rsEdit["ClientCommentsTitle"]; ?>" /></td>
</tr>

<tr>
  <td colspan="5"><textarea name="txtComments"  style="width:550px; height:175px;"><?php echo $rsEdit["ClientComments"]; ?></textarea></td>
</tr>
<tr>
<td colspan="5"><div style=" text-align:center">
<input type="submit" name="submit" value="Edit Project" />
<input type="button" name="Reset" value="Cancel" alt="Cancel" onclick="document.location='/admin/portfolio/index.php'" />
</div></td>
</tr>
</table>
</form>
<?php
}
break;
}
include($_SERVER['DOCUMENT_ROOT'] . '/includes/logged_footer.php');
?>

Link to comment
Share on other sites

156 is  foreach ($_FILES["pictures"]["error"] as $key => $error) {

 

176 is    header("Location: /admin/portfolio/index.php");

 

the image is not meant to go to the page just be checked then uploaded if its ok then page redirected

Link to comment
Share on other sites

156: I think it might be because there aren't any errors? Try checking to see if there are errors first, then foreach'ing them.

 

176: Well, you're trying to send headers after you've outputted (which is all the html before that.)

Link to comment
Share on other sites

how can i check for errors first?

this code isnt mine you see, im jsut trying to fatham it out

i dont fully understand how that for each section works at all :S

 

which html is the ouputted stuff, i still havent got the hang of that either...

Link to comment
Share on other sites

ok so now i have

 

if ($_FILES["pictures"]["error"] > 0) {  
$error=0;
  foreach ($_FILES["pictures"]["error"] as $key => $error) {
  $file_name =  $_FILES["pictures"]['name'][$error]; // can call this anything you like this will take the original name
  $file =  $_FILES["pictures"]['tmp_name'][$error];
  $file_size = $_FILES["pictures"]['size'][$error];
      if (($size_limit == "yes") && ($limit_size < $file_size)) {
        header("Location: /admin/portfolio/edit_project.php?error=filesize");
        } else {
        $ext = strrchr($file_name,'.');
          if (($limit_ext == "yes") && (!in_array($ext,$extensions))) {
        header("Location: /admin/portfolio/edit_project.php?error=filetype");
          }else{
          $j = $error + 1;
          // first move the file to
          move_uploaded_file($file, $absolute_path.$file_name);
          // Save full size image with max width/height
          resampleimage("175", $absolute_path.$file_name, $absolute_path.$file_name, 0); 
        }
        }
  $error++;
  }
}

and

 

Warning: Cannot modify header information - headers already sent by (output started at /home/fhlinux153/c/cwservicesltd.co.uk/user/htdocs/admin/portfolio/edit_project.php:19) in /home/fhlinux153/c/cwservicesltd.co.uk/user/htdocs/admin/portfolio/edit_project.php on line 165

 

Warning: Cannot modify header information - headers already sent by (output started at /home/fhlinux153/c/cwservicesltd.co.uk/user/htdocs/admin/portfolio/edit_project.php:19) in /home/fhlinux153/c/cwservicesltd.co.uk/user/htdocs/admin/portfolio/edit_project.php on line 165

 

Warning: Cannot modify header information - headers already sent by (output started at /home/fhlinux153/c/cwservicesltd.co.uk/user/htdocs/admin/portfolio/edit_project.php:19) in /home/fhlinux153/c/cwservicesltd.co.uk/user/htdocs/admin/portfolio/edit_project.php on line 165

 

Warning: Cannot modify header information - headers already sent by (output started at /home/fhlinux153/c/cwservicesltd.co.uk/user/htdocs/admin/portfolio/edit_project.php:19) in /home/fhlinux153/c/cwservicesltd.co.uk/user/htdocs/admin/portfolio/edit_project.php on line 165

 

Warning: Cannot modify header information - headers already sent by (output started at /home/fhlinux153/c/cwservicesltd.co.uk/user/htdocs/admin/portfolio/edit_project.php:19) in /home/fhlinux153/c/cwservicesltd.co.uk/user/htdocs/admin/portfolio/edit_project.php on line 177

 

165 is    header("Location: /admin/portfolio/edit_project.php?error=filetype");

177 is    header("Location: /admin/portfolio/index.php");

Link to comment
Share on other sites

problem is you have the code executing before you have sent any files through the form. So there is no array to run in the foreach statement.

 

The header is erroring because output is being sent by the foreach error.

 

It is my code and it works fine, you just need to do a check to see if the form has been submitted before you run the loop.

 

Ray

 

EDIT i stand corrected I missed the switch part. :)

Link to comment
Share on other sites

i knew someone gave me it on here

 

thanks for it, i think i have broke it changing things :S

 

this my full page now.

 

this look bettter coded?

it seems to work now aswell

well i havent tried uploading an image but i can edit the other fields and post it

 

<?php
function searchForThis($data, $search){
if (strstr($data, $search)){
	echo 'checked="checked"';}
}
$absolute_path = $_SERVER['DOCUMENT_ROOT'] . "/portfolio/images/";//Absolute path to where files are uploaded
$thumb_path = $_SERVER['DOCUMENT_ROOT'] . "/portfolio/images/thumbs/";   //Absolute path to where thumbs are to be stored if you want this
$size_limit = "yes";                                          //do you want a size limit yes or no.
$limit_size = "4000000";                                       //How big do you want size limit to be in bytes
$limit_ext = "yes";                                           //do you want to limit the extensions of files uploaded
$ext_count = "4";                                             //total number of extensions in array below
$extensions = array(".jpg", ".jpeg", ".png", ".gif");         //List extensions you want files uploaded to be

function resampleimage($maxsize, $sourcefile, $destination, $imgcomp=0){
// SET THE IMAGE COMPRESSION
$g_imgcomp=100-$imgcomp;
  // CHECK TO SEE IF THE IMAGE EXISTS FIRST
  if(file_exists($sourcefile)){
  // FIRST WE GET THE CURRENT IMAGE SIZE
  $g_is=getimagesize($sourcefile);
    /********* CALCULATE THE WIDTH AND THE HEIGHT ***************/
    // CHECK TO SEE IF THE WIDTH AND HEIGHT ARE ALREADY SMALLER THAN THE MAX SIZE
    if($g_is[0] <= $maxsize && $g_is[1] <= $maxsize){
    // LEAVE WIDTH AND HEIGHT ALONE IF IMAGE IS SMALLER THAN MAXSIZE
    $new_width=$g_is[0];
    $new_height=$g_is[1];
    } else {
    // GET VALUE TO CALCULATE WIDTH AND HEIGHT
    $w_adjust = ($maxsize / $g_is[0]);
    $h_adjust = ($maxsize / $g_is[1]);
      // CHECK TO WHICH DIMENSION REQUIRES THE SMALLER ADJUSTMENT
      if($w_adjust <= $h_adjust){
      // CALCULATE WIDTH AND HEIGHT IF THE WIDTH VALUE IS SMALLER
      $new_width=($g_is[0]*$w_adjust);
      $new_height=($g_is[1]*$w_adjust);
      } else {
      // CALCULATE WIDTH AND HEIGHT IF THE HEIGHT VALUE IS SMALLER
      $new_width=($g_is[0]*$h_adjust);
      $new_height=($g_is[1]*$h_adjust);
      }
    }
  //SEARCHES IMAGE NAME STRING TO SELECT EXTENSION (EVERYTHING AFTER THE LAST "." )
$image_type = strrchr($sourcefile, ".");

//SWITCHES THE IMAGE CREATE FUNCTION BASED ON FILE EXTENSION
switch($image_type) {
	case '.jpg':
		$img_src = imagecreatefromjpeg($sourcefile);
		break;
	case '.jpeg':
		$img_src = imagecreatefromjpeg($sourcefile);
		break;
	case '.png':
		$img_src = imagecreatefrompng($sourcefile);
		break;
	case '.gif':
		$img_src = imagecreatefromgif($sourcefile);
		break;
	default:
		echo("Error Invalid Image Type");
		die;
		break;
}
  // CREATE THE TRUE COLOR IMAGE WITH NE WIDTH AND HEIGHT
  $img_dst=imagecreatetruecolor($new_width,$new_height);
  // RESAMPLE THE IMAGE TO NEW WIDTH AND HEIGHT
  imagecopyresampled($img_dst, $img_src, 0, 0, 0, 0, $new_width, $new_height, $g_is[0], $g_is[1]);
  // OUTPUT THE IMAGE AS A JPEG.
  // THIS CAN BE CHANGED IF YOU WANT TRANSPARENCY OR PREFER ANOTHER FORMAT. MAKE SURE YOU CHANGE HEADER ABOVE.
  imagejpeg($img_dst, $destination, 100);
  // DESTROY THE NEW IMAGE
  imagedestroy($img_dst);
  return true;
  } else {
  return false;
  }
}

switch(@$_GET["action"]) {
Case "edit":
include($_SERVER['DOCUMENT_ROOT'] . '/includes/connection.php');

$PortID = $_POST["txtID"];
$Type = $_POST["SelType"];
$Company = $_POST["txtCompany"];
$Name = $_POST["txtName"];
$URL = $_POST["txtUrl"];
$Location = $_POST["txtLocation"];
$Logo = $_FILES['pictures']['name'][0];
$Image1 = $_FILES['pictures']['name'][1];
$Image2 = $_FILES['pictures']['name'][2];
$Image3 = $_FILES['pictures']['name'][3];
$Case = $_POST["txtCase"];
$Result = $_POST["txtResult"];
$Brief = $_POST["txtBrief"];
$CommentsTitle = $_POST["txtCommentsTitle"];
$Comments = $_POST["txtComments"];
$Date = date("yyyy-mm-dd");

if (!empty($_POST["chkXHTML"])) {
$Services = ":".$_POST["chkXHTML"].":";}
if (!empty($_POST["chkWebDesign"])) {
$Services = $Services.":".$_POST["chkWebDesign"].":";}
if (!empty($_POST["chkCMS"])) {
$Services = $Services.":".$_POST["chkCMS"].":";}
if (!empty($_POST["chkOnlineDB"])) {
$Services = $Services.":".$_POST["chkOnlineDB"].":";}
if (!empty($_POST["chkPDF"])) {
$Services = $Services.":".$_POST["chkPDF"].":";}
if (!empty($_POST["chkMembership"])) {
$Services = $Services.":".$_POST["chkMembership"].":";}
if (!empty($_POST["chkBranding"])) {
$Services = $Services.":".$_POST["chkBranding"].":";}

$SQL = "UPDATE tblPortfolio Set PortType='$Type', ClientCompany='$Company', ClientName='$Name', ClientUrl='$URL', ClientLocation='$Location', ";

if (!empty($Logo)) {
$SQL = $SQL."ClientLogo='$Logo', ";
}
if (!empty($PortImage1)) {
$SQL = $SQL."PortImage1='$Image1', ";
}
if (!empty($PortImage2)) {
$SQL = $SQL."PortImage2='$Image2', ";
}
if (!empty($PortImage3)) {
$SQL = $SQL."PortImage3='$Image3', ";
}

$SQL = $SQL."ClientCase='$Case', ClientResult='$Result', ClientBrief='$Brief', ClientServices='$Services',  ClientCommentsTitle='$CommentsTitle', ClientComments='$Comments', PortDateEdited='$Date' WHERE PortID='$PortID' ";

mysql_query($SQL) or die(mysql_error());
if ($_FILES["pictures"]["error"] > 0) {  
$error=0;
  foreach ($_FILES["pictures"]["error"] as $key => $error) {
  $file_name =  $_FILES["pictures"]['name'][$error]; // can call this anything you like this will take the original name
  $file =  $_FILES["pictures"]['tmp_name'][$error];
  $file_size = $_FILES["pictures"]['size'][$error];
      if (($size_limit == "yes") && ($limit_size < $file_size)) {
        header("Location: /admin/portfolio/edit_project.php?error=filesize");
        } else {
        $ext = strrchr($file_name,'.');
          if (($limit_ext == "yes") && (!in_array($ext,$extensions))) {
        header("Location: /admin/portfolio/edit_project.php?error=filetype");
          }else{
          $j = $error + 1;
          // first move the file to
          move_uploaded_file($file, $absolute_path.$file_name);
          // Save full size image with max width/height
          resampleimage("175", $absolute_path.$file_name, $absolute_path.$file_name, 0); 
        }
        }
  $error++;
  }
}
    header("Location: /admin/portfolio/index.php");
break;
default:
include($_SERVER['DOCUMENT_ROOT'] . '/includes/header.php');
include($_SERVER['DOCUMENT_ROOT'] . '/includes/admin_access.inc');
?>
<div id="subs-container">
<div id="subs">
<div id="subs-admin-text">
<div class="padding">
<ul>
<li class="menu">Portfolio Menu:</li>
<li class="menu"><a href="/admin/portfolio/add_project.php">Add</a></li>
<li class="menu"><a href="/admin/portfolio/index.php">View/Edit</a></li>
<li class="menu"><a href="/admin/portfolio/current_projects.php">Current Projects</a></li>
</ul>
</div>
</div>
</div>
</div>
<div id="lower-container">
<div id="backlinks"><?php include($_SERVER['DOCUMENT_ROOT'] . '/includes/backlinks.php'); ?></div>
<div id="content">
<div class="padding">
<?
function showimagesize($im){
    $Imagesize = getimagesize($_SERVER['DOCUMENT_ROOT']."/portfolio/images/".$im."");
    $width = $Imagesize[0] + 40; 
    $height = $Imagesize[1] + 40;
    echo   "<a href=\"/portfolio/images/$im\" onclick=\"NewWindow(this.href,'name','$width','$height','yes');return false\">$im</a>";
}

$extens = '';

        if (($extensions == "") or ($extensions == " ") or ($ext_count == "0") or ($ext_count == "") or ($limit_ext != "yes") or ($limit_ext == "")) {
           $extens = "any extension";
        } else {
        $ext_count2 = $ext_count+1;
        for($counter=0; $counter<$ext_count; $counter++) {
            $extens .= "  $extensions[$counter]";
        }
        }
        if (($limit_size == "") or ($size_limit != "yes")) {
            $limit_size = "any size";
        } else {
            $limit_size .= " bytes";
            $mb_size = ($limit_size/1000000);
        }
        $pichead = "<ul style=\"color:#FF0000; font-size:10px;\"><li style=\"display:inline; padding-right:10px;\">File extension must be $extens |</li>";
        $pichead .="<li style=\"display:inline; padding-right:10px;\">Maximum file size is $limit_size ($mb_size MB) |</li>
        			<li style=\"display:inline; padding-right:10px;\">No spaces in the filename</li></ul>";

$ID = $_GET["ID"];

$PortSQL = mysql_query("SELECT * FROM tblPortfolio WHERE PortID='$ID' ") or die(mysql_error());

while ($rsEdit = mysql_fetch_array($PortSQL)) {
?>
<script type="text/javascript">
bkLib.onDomLoaded(function() {
new nicEditor({xhtml:true}).panelInstance('txtCase');	
new nicEditor({xhtml:true}).panelInstance('txtResult');	
new nicEditor({xhtml:true}).panelInstance('txtBrief');	
new nicEditor({xhtml:true}).panelInstance('txtComments');	
});
</script>
<h3>Edit Project</h3>
<form action="<?=$_SERVER['PHP_SELF']?>?action=edit" method="post" enctype="multipart/form-data" />
<input name="txtID" type="hidden"  value="<?php echo $rsEdit["PortID"]; ?>" />
<table width="100%">
<tr>
  <td><strong>Project Type:</strong></td>
  <td colspan="4"><select name="SelType">
  <option><?php echo $rsEdit["PortType"]; ?></option>
    <option>Marketing</option>
    <option>Technical</option>
    <option>Web Design</option>
  </select>  </td>
</tr>
<tr>
  <td><strong>Company Name:</strong></td>
  <td colspan="4"><input name="txtCompany" type="text" size="50" value="<?php echo $rsEdit["ClientCompany"]; ?>" /></td>
</tr>
<tr>
  <td><strong>Client Name</strong></td>
  <td colspan="4"><input name="txtName" type="text" id="txtName" size="50" value="<?php echo $rsEdit["ClientName"]; ?>" /></td>
</tr>


<tr>
  <td><strong>Client Location</strong></td>
  <td colspan="4"><input name="txtLocation" type="text" id="txtLocation" size="50" value="<?php echo $rsEdit["ClientLocation"]; ?>" /></td>
</tr>
<tr>
  <td><strong>Url:</strong></td>
  <td colspan="4"><input name="txtUrl" type="text" size="70" value="<?php echo $rsEdit["ClientUrl"]; ?>" /></td>
</tr>
<tr>
  <td><strong>Client Logo:</strong></td>
  <td><input type="file" name="pictures[]" size="50" /></td>
  <td>Current Logo:</td>
  <td><?php showimagesize($rsEdit["ClientLogo"]); ?></td>
</tr>
<tr><td><strong>Image 1:</strong></td><td><input type="file" name="pictures[]" size="50" /></td>
  <td>Current Image 1</td>
  <td><?php showimagesize($rsEdit["PortImage1"]); ?></td>
</tr>
<tr><td><strong>Image 2:</strong></td><td><input type="file" name="pictures[]" size="50" /></td>
  <td>Current Image 2</td>
  <td><?php showimagesize($rsEdit["PortImage2"]); ?></td>
</tr>
<tr><td><strong>Image 3:</strong></td><td><input type="file" name="pictures[]" size="50" /></td>
  <td>Current Image 3</td>
  <td><?php showimagesize($rsEdit["PortImage3"]); ?></td>
</tr>
<tr>
  <td colspan="5"><? echo $pichead; ?></td>
</tr>
<tr>
  <td colspan="5"><strong>Client Brief / About the Client:</strong></td>
</tr>
<tr>
  <td colspan="5"><textarea name="txtBrief" style="width:550px; height:175px;"><?php echo $rsEdit["ClientBrief"]; ?></textarea></td>
<tr>
<tr>
  <td colspan="5"><strong>What the client wanted:</strong></td>
</tr>
<tr>
  <td colspan="5"><textarea name="txtCase" style="width:550px; height:175px;"><?php echo $rsEdit["ClientCase"]; ?></textarea></td>
<tr>
  <td colspan="5"><strong>Case result:</strong></td>
</tr>
<tr>
  <td colspan="5"><textarea name="txtResult" style="width:550px; height:175px;"><?php echo $rsEdit["ClientResult"]; ?></textarea></td>
<tr>
  <td colspan="5"><strong>Client Services</strong></td>
<tr>
  <td colspan="5">
<?php $data = $rsEdit["ClientServices"]; ?>
  <table width="50%" border="0">
    <tr>
      <td>XHTML/CSS Standards Compliant</td>
      <td><input type="checkbox" name="chkXHTML" value="XHTML/CSS Standards Compliant" class="blank"
       <?php $search = "XHTML/CSS Standards Compliant"; searchForThis($data, $search);?> /></td>
      <td>Form to PDF/Email</td>
      <td><input type="checkbox" name="chkPDF" value="Form to PDF/Email" class="blank"
      <?php $search = "Form to PDF/Email"; searchForThis($data, $search);?>  /></td>
    </tr>
    <tr>
      <td>Webpage Design</td>
      <td><input type="checkbox" name="chkWebDesign" value="Webpage Design" class="blank" id="chkWebDesign"
      <?php $search = "Webpage Design"; searchForThis($data, $search);?> /></td>
      <td>Membership System</td>
      <td><input type="checkbox" name="chkMembership" value="Membership System" class="blank"
      <?php $search = "Membership System"; searchForThis($data, $search);?> /></td>
    </tr>
    <tr>
      <td>Content Management System</td>
      <td><input type="checkbox" name="chkCMS" value="Content Mangement System" class="blank"
      <?php $search = "Content Mangement System"; searchForThis($data, $search);?> /></td>
      <td>Corporate Branding</td>
      <td><input type="checkbox" name="chkBranding" value="Corporate Branding" class="blank"
      <?php $search = "Corporate Branding"; searchForThis($data, $search);?> /></td>
    </tr>
    <tr>
      <td>Online Database</td>
      <td><input type="checkbox" name="chkOnlineDB" value="Online Database" class="blank"
      <?php $search = "Online Database"; searchForThis($data, $search);?> /></td>
      <td> </td>
      <td> </td>
    </tr>
  </table>  </td>
</tr>
<tr>
  <td> </td>
  <td colspan="4"> </td>
</tr>
<tr>
  <td><strong>Client Comments:</strong></td>
  <td colspan="4"><input name="txtCommentsTitle" type="text" size="50" value="<?php echo $rsEdit["ClientCommentsTitle"]; ?>" /></td>
</tr>

<tr>
  <td colspan="5"><textarea name="txtComments"  style="width:550px; height:175px;"><?php echo $rsEdit["ClientComments"]; ?></textarea></td>
</tr>
<tr>
<td colspan="5"><div style=" text-align:center">
<input type="submit" name="submit" value="Edit Project" />
<input type="button" name="Reset" value="Cancel" alt="Cancel" onclick="document.location='/admin/portfolio/index.php'" />
</div></td>
</tr>
</table>
</form>
<?php
}
include($_SERVER['DOCUMENT_ROOT'] . '/includes/logged_footer.php');
break;
}
?>

Link to comment
Share on other sites

also the thing i cant understand about headers is this

 

this is another one of my pages according to the way the headers error keeps happenign this page shoudl not work, but it does perfectly, this is what i dont understand, can anyone enlighten me on this too? cheers

 

<?php
include($_SERVER['DOCUMENT_ROOT'] . '/includes/header.php');
include($_SERVER['DOCUMENT_ROOT'] . '/includes/admin_access.inc');
?>
<div id="subs-container">
<div id="subs">
<div id="subs-admin-text">
<div class="padding">
<ul>
<li class="menu">Portfolio Menu:</li>
<li class="menu"><a href="/admin/portfolio/add_project.php">Add</a></li>
<li class="menu"><a href="/admin/portfolio/index.php">View/Edit</a></li>
<li class="menu"><a href="/admin/portfolio/current_projects.php">Current Projects</a></li>
</ul>
</div>
</div>
</div>
</div>
<div id="lower-container">
<div id="backlinks"><?php include($_SERVER['DOCUMENT_ROOT'] . '/includes/backlinks.php'); ?></div>
<div id="content">
<div class="padding">
<?php

switch(@$_GET["action"]) {
Case "delete":

$PortID = $_GET["ID"];

mysql_query("DELETE FROM tblPortfolio WHERE PortID='$PortID'") or die(mysql_error());
header("Location: /admin/portfolio/index.php");
break;

Case "current";

if(is_array($_POST['checkbox'])){
  foreach($_POST['checkbox'] as $PortID){
    mysql_query("UPDATE tblPortfolio SET PortCurrent='1' WHERE PortID='$PortID'") or die(mysql_error());
  }
}
header("Location: /admin/portfolio/current_projects.php");

break;
Default:
echo "<h3>Portfolio</h3>";
echo "<p>Edit, Archive and Delete Projects using the below navigation.</p>";

$PortSQL = mysql_query("SELECT * FROM tblPortfolio WHERE PortCurrent='0' ORDER BY PortDateAdded DESC") or die(mysql_error());

echo '<form id="archive" method="post" action="'.$_SERVER['PHP_SELF'].'?action=current">'."\n";
echo '<table width="100%"><tr style="font-weight:bold;"><td class="center">Type</td><td>Project Title</td><td class="center">Date Added</td><td class="center">Date Modified</td><td class="center">Edit</td><td class="center">Current</td><td class="center">Delete</td></tr>'."\n";

while ($rsPort = mysql_fetch_array($PortSQL)) {

echo '<tr><td class="center">';
echo substr($rsPort['PortType'],0,1);
echo '</td><td>';
echo $rsPort["ClientCompany"]."</td><td class=\"center\">";
mydate($rsPort["PortDateAdded"]);
echo'</td><td class="center">';
if (empty($rsPort["PortDateEdited"])) {
echo " "; }
else {
mydate($rsPort["PortDateEdited"]);
}
echo '</td><td class="center"><a href="/admin/portfolio/edit_project.php?ID='.$rsPort["PortID"].' ">Edit</a></td>';
echo '<td style="text-align:center;"><input name="checkbox[]" type="checkbox" id="checkbox[]" class="blank" value="'.$rsPort['PortID'].' \"></td>';
echo '<td class="center"><a href="?action=delete&ID='.$rsPort["PortID"].' ">Delete</a></td>';
echo "</tr>"."\n";
} 
echo '<tr style="height:50px;"><td colspan="6" style="text-align:right;"><input type="submit" value="Add to Current Projects" /></td></tr> ';
echo "</table></form>";
}
include($_SERVER['DOCUMENT_ROOT'] . '/includes/logged_footer.php');
?> 

Link to comment
Share on other sites

I did notice you checged or forgot something in the loop

since it is an array you need to increment the array keys to loop correctly

$i=0; // took this out
    foreach ($_FILES["pictures"]["error"] as $key => $error) {
    $file_name =  $_FILES["pictures"]['name'][$i]; // checnged them to $error should be $i
    $file =  $_FILES["pictures"]['tmp_name'][$i];
    $file_size = $_FILES["pictures"]['size'][$i];
      if (($size_limit == "yes") && ($limit_size < $file_size)) {
      header("Location: /admin/portfolio/edit_project.php?error=filesize");
      } else {
      $ext = strrchr($file_name,'.');
        if (($limit_ext == "yes") && (!in_array($ext,$extensions))) {
        header("Location: /admin/portfolio/edit_project.php?error=filetype");
        }else{
        $j = $error + 1;
        // first move the file to
        move_uploaded_file($file, $absolute_path.$file_name);
        // Save full size image with max width/height
        resampleimage("175", $absolute_path.$file_name, $absolute_path.$file_name, 0);
        }
      }
    $i++;  // increment the counter
    $error++;
    }

 

Ray

 

Link to comment
Share on other sites

thats made it work again :)

 

hopefully there will be no more errors, or are there some that you can see also to clarfiy below is jsut an exampl of how alot of thigns work on my site and this is wrong?

 

if im redirecting i have to have the header and footer in each case?

 

thanks

 

<?php
include($_SERVER['DOCUMENT_ROOT'] . '/includes/header.php');
include($_SERVER['DOCUMENT_ROOT'] . '/includes/admin_access.inc');
?>
<div id="subs-container">
<div id="subs">
<div id="subs-admin-text">
<div class="padding">
<ul>
<li class="menu">Portfolio Menu:</li>
<li class="menu"><a href="/admin/portfolio/add_project.php">Add</a></li>
<li class="menu"><a href="/admin/portfolio/index.php">View/Edit</a></li>
<li class="menu"><a href="/admin/portfolio/current_projects.php">Current Projects</a></li>
</ul>
</div>
</div>
</div>
</div>
<div id="lower-container">
<div id="backlinks"><?php include($_SERVER['DOCUMENT_ROOT'] . '/includes/backlinks.php'); ?></div>
<div id="content">
<div class="padding">
<?php

switch(@$_GET["action"]) {
Case "1":
//code
header("Location: /case1.php");
break;
Case "2";
//code
header("Location: /case2.php");
break;
Default:
//code
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?action=case1" method="post">
<table>
<tr>
<td>Name:</td><td><input name="txtName" type="text" /></td>
<td colspan="2"><input name="submit" type="submit" /></td>
</tr>
</table>
</form>
<?php
break;
}
include($_SERVER['DOCUMENT_ROOT'] . '/includes/logged_footer.php');
?> 

Link to comment
Share on other sites

The code above should in fact fail but only if your header.php or admin_access files are outputting something to the browser.

 

You can change it to something like this in order to make sure

<?php
switch(@$_GET["action"]) {
Case "1":
//code
header("Location: /case1.php");
break;
Case "2";
//code
header("Location: /case2.php");
break;
Default:
//code
include($_SERVER['DOCUMENT_ROOT'] . '/includes/header.php');
include($_SERVER['DOCUMENT_ROOT'] . '/includes/admin_access.inc');
?>
<div id="subs-container">
<div id="subs">
<div id="subs-admin-text">
<div class="padding">
<ul>
<li class="menu">Portfolio Menu:</li>
<li class="menu"><a href="/admin/portfolio/add_project.php">Add</a></li>
<li class="menu"><a href="/admin/portfolio/index.php">View/Edit</a></li>
<li class="menu"><a href="/admin/portfolio/current_projects.php">Current Projects</a></li>
</ul>
</div>
</div>
</div>
</div>
<div id="lower-container">
<div id="backlinks"><?php include($_SERVER['DOCUMENT_ROOT'] . '/includes/backlinks.php'); ?></div>
<div id="content">
<div class="padding">

<form action="<?php echo $_SERVER['PHP_SELF']; ?>?action=case1" method="post">
<table>
<tr>
<td>Name:</td><td><input name="txtName" type="text" /></td>
<td colspan="2"><input name="submit" type="submit" /></td>
</tr>
</table>
</form>
<?php
include($_SERVER['DOCUMENT_ROOT'] . '/includes/logged_footer.php');
break;
}
?>

 

Ray

Link to comment
Share on other sites

This is only the case when you are using any kind of php header function. headers have to be the first thing that gets outputted to the page other wise you will get an error. Doesn't matter if it is a form or not. Your header.php page is essentially a php script outputting html, once you output html you can no longer use a php header redirect. Also header Location functions are immediate, so no need to output anything after anyway.

 

If you want to redirect someone after you have outputted something to the browser, use a meta tag

echo "<META HTTP-EQUIV=\"Refresh\" content=\"1;url=somepage.php\" />

 

can change the 1 to any number of seconds you want to wait for the redirect.

 

Ray

Link to comment
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.