Jump to content

$i++ photo url


LM

Recommended Posts

I'm having a problem understanding how to import more than one photo in a list of up to 20 photos.  I can only import 1 photo from a comma delimited csv with a pipe between each photo url.

 

<?

function getImg($value,$userid, $stocknum){

  $photoStr = '';

  if($value !=''){

      $photoURLs = explode('|', $value);

      for($i=0; $i<count($photoURLs);$i++){

        $url = $photoURLs[$i];

        $j = $i+1;

        if (@copy($url, "../upload/".$userid."/".$userid."_".$stocknum."_".$j.".jpg")) {

            $photoStr .= $userid."_".$stocknum."_".$j.".jpg|";

        }

      }

  }

  return $photoStr;

}

?>

 

And after csv and sql

<? if($img){

    $img = rtrim($img, '|');

    $imgArray = explode('|', $img);

    $imgIndex = 1;

    foreach ($imgArray AS $imgItem){

      $db->query("UPDATE `stockitem` SET img".$imgIndex."= '$imgItem' where stocknum='$stocknum'","" , __FILE__, __LINE__);

      $imgIndex++;

    }

    }

?>

Any help would be appreciated.

Link to comment
Share on other sites

I'm having a problem understanding how to import more than one photo in a list of up to 20 photos.  I can only import 1 photo from a comma delimited csv with a pipe between each photo url.

 

<?
function getImg($value,$userid, $stocknum){
   $photoStr = '';
   if($value !=''){
      $photoURLs = explode('|', $value);
      for($i=0; $i<count($photoURLs);$i++){
         $url = $photoURLs[$i];
         $j = $i+1;
         if (@copy($url, "../upload/".$userid."/".$userid."_".$stocknum."_".$j.".jpg")) {
             $photoStr .= $userid."_".$stocknum."_".$j.".jpg|";
         }
      }
   }
   return $photoStr;
}
?>

And after csv and sql 
<? if($img){
     $img = rtrim($img, '|');
     $imgArray = explode('|', $img);
     $imgIndex = 1;
     foreach ($imgArray AS $imgItem){
      $db->query("UPDATE `stockitem` SET img".$imgIndex."= '$imgItem' where stocknum='$stocknum'","" , __FILE__, __LINE__);
      $imgIndex++;
     }
    }
?>

Any help would be appreciated.

 

So after running this, if you echo $photoStr what do you get?

 

Also, where does $img get created?

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.