4
Next guys, I’m adapting a file upload system to php. All the bulk has already been created, Insert and update and such, but in the middle of the logic needing a conditional to check if the input file field was used, if it is empty do nothing, if it is filled do the update. I have the partial solution they gave me that was this:
if ($_POST['file'] != '') {
UPDATE
}
But I’m using php and the upload field comes from an array as follows
<input type="file" id="file1" name="file1[]"></input>
How do I write this if considering the current loop ?
My bow tie code is like this today:
if($numFile <= 0){ //Laço que vai servir pra checar se o input está vazio
echo 'Selecione uma Imagem!';
}else{
for($i = 0; $i < $numFile; $i++){
$name = $file['name'][$i];
$type = $file['type'][$i];
$size = $file['size'][$i];
$error = $file['error'][$i];
$tmp = $file['tmp_name'][$i]; .... e o programa segue
I needed to somehow check if the input is empty, if the value is set in the $numFile then I do the Update or not, all the rest of the program is working, already with bank images and everything. The problem is that without it is conditional, independent of already having an upada image, if I click upload without submitting a photo it will overwrite my bank with white space
Hmm, Testing...
– user7013
Test but it did not work, to simplify I used like this: <pre> $file2= $_FILES['file1']; // treat this value as an array foreach( $file2 as $esteFile ) { if( $esteFile != ') { $numFile = 0; } } </pre> if($numFile <= 0){ echo 'Select an Image! '; }Else{
– user7013
Sorry for the formatting, I’m still learning to use the stackoverflow, I’m a first-time sailor.
– user7013