graham23s Posted September 7, 2007 Share Posted September 7, 2007 Hi Guys, what i'm trying to do is grab the file contents from some files that are uploaded for example: $content = file_get_contents("file/$renamed_file"); $file_for_mysql = mysql_real_escape_string($content); if i put this in a foreach and try to echo it out i get nothing but if i take it out the foreach i get the file contents from 1 of the files, but not them all. extra code: foreach($_FILES['files']['name'] as $key => $value) { $new_nfo_name = basename($value); $random_number_again = rand(00000000,99999999); $renamed_file = ("$random_number_again.txt"); $target_path2 = "files/"; $target_path2 = $target_path2.$renamed_file; //echo $target_path2; if(move_uploaded_file($_FILES['files']['tmp_name'][$key], $target_path2)) { } $content = file_get_contents("file/$renamed_file"); $file_for_mysql = mysql_real_escape_string($content); echo $file_for_mysql; } maybe my foreach was wrong, the user can specify from 2-5 how many uploads they want to do, i was wanting to be able to read the files and store all the contents into mysql, works well enough with 1 file but need to do with all the files uploaded. any help would be appreciated Graham Quote Link to comment https://forums.phpfreaks.com/topic/68406-solved-foreach-problem/ Share on other sites More sharing options...
lemmin Posted September 7, 2007 Share Posted September 7, 2007 You are using the variable "name" inside the arrays as the array parameter for foreach. You need to use just the array, like $_FILES. foreach($_FILES as $key => $value) { echo $value['name']; } I think the $key is just going to be an incremented integer, so it isn't really necessary. Quote Link to comment https://forums.phpfreaks.com/topic/68406-solved-foreach-problem/#findComment-343921 Share on other sites More sharing options...
graham23s Posted September 7, 2007 Author Share Posted September 7, 2007 Hi Mate, tried: foreach($_FILES['files']['name'] as $keys => $values) { $file = basename($values); $content = file_get_contents("$file"); $file_for_mysql = mysql_real_escape_string($content); echo $file_for_mysql; } this isnt retrieving anything from: $content = file_get_contents("$file"); $file_for_mysql = mysql_real_escape_string($content); im stumped lol Graham Quote Link to comment https://forums.phpfreaks.com/topic/68406-solved-foreach-problem/#findComment-343987 Share on other sites More sharing options...
lemmin Posted September 7, 2007 Share Posted September 7, 2007 You didn't even do what I suggested. Use "$_FILES" instead of "$_FILES['files']['names']". Then the $values will be arrays containing information about the files, like I showed in my previous post. Quote Link to comment https://forums.phpfreaks.com/topic/68406-solved-foreach-problem/#findComment-343989 Share on other sites More sharing options...
enerjiza Posted September 7, 2007 Share Posted September 7, 2007 I believe you need to do the following: foreach ($_FILES['files'] AS $key=>$val) { echo $key . ': ' . $val; } I believe that should output all the file information you're looking for; name, size, and type. Let me know if that doesn't work. Quote Link to comment https://forums.phpfreaks.com/topic/68406-solved-foreach-problem/#findComment-344004 Share on other sites More sharing options...
lemmin Posted September 7, 2007 Share Posted September 7, 2007 That code will only give the information for one file, he wants all of the files, I think. Quote Link to comment https://forums.phpfreaks.com/topic/68406-solved-foreach-problem/#findComment-344008 Share on other sites More sharing options...
graham23s Posted September 7, 2007 Author Share Posted September 7, 2007 ahh sorry guys im bein a bit slow tonight lol i managed to get it fixed thanks again guiys. Graham Quote Link to comment https://forums.phpfreaks.com/topic/68406-solved-foreach-problem/#findComment-344019 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.