Jump to content

foreach and while problem


feri_soft

Recommended Posts

I have 2 arrays:

[code=php]
<?php
foreach ($_FILES[images][name] as $img) {
  $ext123  = substr(strrchr($img, "."), 1);
if(($ext123 == "jpg") || ($ext123 == "jpeg") || ($ext123 == "gif")){
}else{
  $error[] = "ERROR";
}
}?>[/code]

which is before my database query

and
[code=php]<?php while(list($key1,$value1) = each($_FILES[images][name]))
{
if(!empty($value1))
{
$ext1 = substr(strrchr($value1, "."), 1);

$filename = $idlast . ' - ' . $key1 . '.' . $ext1;
echo $filename;
$add = "upload/$filename";
                     
     
copy($_FILES[images][tmp_name][$key1], $add);
$add = trashinput($add);
$fq = "UPDATE listings SET img". $key1 ." = '$add' WHERE id = '$idlast'";

    mysql_query($fq) or die('Грешка : ' . mysql_error());     

}
}?>[/code]

which is after the query.
The first one checks the file extension and if they are good it proceeds if not it dies. The second is after the query so that i can get the last id and put it as a file name. But when i put the first array check it doesn't want to upload files. When i remove it, it works more than perfect.

Can you tell me where is the problem or suggest another way of uploading with id names ;)
Link to comment
Share on other sites

just having a quick look at your code there I have a question

[code]
<?php
foreach ($_FILES[images][name] as $img) {
    $ext123  = substr(strrchr($img, "."), 1);
if(($ext123 == "jpg") || ($ext123 == "jpeg") || ($ext123 == "gif"))
{
    //what am i to do if the extensions is a jpg/jpeg/gif...you have not told me to do anything
}
else
{
   $error[] = "ERROR";
}
}
?>
[/code]

sorry I have read my post and realised that if they are that then dont throw and error but carry on I will have another think - apologies
Link to comment
Share on other sites

!== means is NOT IDENTICAL TO

!= means NOT EQUAL TO so you could try and use

[code]
<?php
foreach ($_FILES[images][name] as $img)
{
  $ext123  = substr(strrchr($img, "."), 1);
if(($ext123 != "jpg") || ($ext123 != "jpeg") || ($ext123 != "gif"))
{
    $error[] = "ERROR";
}
}
?>
[/code]
Link to comment
Share on other sites

something to that effect maybe?
[code]
<?php
foreach ($_FILES[images][name] as $img) {
$ext123  = substr(strrchr($img, "."), 1);
if(!($ext123 == "jpg") || ($ext123 == "jpeg") || ($ext123 == "gif")) $error[] = "ERROR";
else{
  if(move_uploaded_file($_FILES["images"]["tmp_name"], $img)){
  echo "Magazine Updated!";
  }else $error[] = "ERROR";
}
}
?>
[/code]
Link to comment
Share on other sites

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.