Jump to content

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

 

 

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.