Jump to content

[SOLVED] foreach if statement help


jesushax

Recommended Posts

Hi below is my code for uploading an image

 

this code runs in a if case:edit is met

 

i have some sql that runs before this foreach statement and that excutes fine so i know the problem lies with the below

 

the problem none of the header relcations are working, after the sql has exectued i just get taken to a blank page, is there something wrong with the if statemnts or anything below?

 

Cheers

 

$i=0;
  foreach ($_FILES["pictures"]["error"] as $key => $error) {
  $file_name =  $_FILES["pictures"]['name'][$i]; // can call this anything you like this will take the original name
  $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 = $i + 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++;
  }
    header("Location: /admin/portfolio/index.php");

Link to comment
https://forums.phpfreaks.com/topic/109376-solved-foreach-if-statement-help/
Share on other sites

your using an $i variable which is usually associated with a for loop.

 

the foreach loop is grabbing an associative value

 

$myarray = array('a' => 'apple', 'b' => 'bobbing', 'c' => 'cats');

 

foreach($myarray as $key=>$value) {

 

echo "<br> $key . " " . $value <br>";

}

 

results:

a apple

b bobbing

c cats

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.