mysql - PHP for loop update database images -
i using loop validate page in php using move_uploaded_file
move uploaded file + add image path database. below code.
if(empty($_files) === false) { for($i=1; $i<=$items; $i++) { $allowed = array('jpg', 'jpeg', 'gif', 'png'); if (empty($_files['photo{$i}']['name']) === true) { echo '<div class="alert alert-danger">please choose file.</div>'; } else { if (in_array(strtolower(end(explode('.', $_files['photo{$i}']['name']))), $allowed) === false) { echo '<div class="alert alert-danger">[photo '.$i.'] format <strong>not</strong> acceptable. '; echo 'accepted formats: '. implode(', ', $allowed).'</div>'; } elseif($_files["photo{$i}"]['size'] > 1048576) { echo '<div class="alert-danger">[photo '.$i.'] image big. maximium file size 1mb.</div>'; } else { mysqli_query($con, "update temp set photo{$i} = '".rand(0,999).".".in_array(strtolower(end(explode('.', $_files['photo{$i}']['name']))))."' session = $session"); move_uploaded_file($_files["photo{$i}"]['tmp_name'], 'img/temp/'.rand(0,999) . '.' . in_array(strtolower(end(explode('.', $_files['photo{$i}']['name']))))); } } } }
the image doesn't move desired uploaded location , not update file path in database. please can help?
everywhere have 'photo{$i}'
incorrect. elitechief21 explained in comment above, php not parse variables in single quotes., literally looking key photo{$i}
in $_files
, treating {$i}
literal text. of course, doesn't exist, script doesn't work expected.
you need use double quotes wherever photo{$i}
inside single quotes.
Comments
Post a Comment