jesushax Posted June 9, 2008 Share Posted June 9, 2008 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 More sharing options...
hansford Posted June 9, 2008 Share Posted June 9, 2008 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 Link to comment https://forums.phpfreaks.com/topic/109376-solved-foreach-if-statement-help/#findComment-561016 Share on other sites More sharing options...
jesushax Posted June 9, 2008 Author Share Posted June 9, 2008 im even more confused then when i started now lol :| so for my code i need to do $error if something o im so confused lol Link to comment https://forums.phpfreaks.com/topic/109376-solved-foreach-if-statement-help/#findComment-561021 Share on other sites More sharing options...
hansford Posted June 9, 2008 Share Posted June 9, 2008 change the [$i] to [$key] Link to comment https://forums.phpfreaks.com/topic/109376-solved-foreach-if-statement-help/#findComment-561035 Share on other sites More sharing options...
hansford Posted June 9, 2008 Share Posted June 9, 2008 error: I mean change [$i] to [$error] lol Link to comment https://forums.phpfreaks.com/topic/109376-solved-foreach-if-statement-help/#findComment-561037 Share on other sites More sharing options...
jesushax Posted June 9, 2008 Author Share Posted June 9, 2008 hey seems to have done the trick think i need to do some more research into arrays Thanks Link to comment https://forums.phpfreaks.com/topic/109376-solved-foreach-if-statement-help/#findComment-561069 Share on other sites More sharing options...
hansford Posted June 9, 2008 Share Posted June 9, 2008 That why most of us are here to research, to learn. Link to comment https://forums.phpfreaks.com/topic/109376-solved-foreach-if-statement-help/#findComment-561076 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.