Jump to content

$media_path Help needed DESPERATELY


ecstatica

Recommended Posts

Hello all,

 

I'm tasked with recreating a somewhat ancient website utilizing existing code (I know, I know!).  Everything is working fine talking to the new database; the only problem is uploading images.  Everything seems to be good with the exception of the media path.    It looks to me as if the uploaded images are supposed to be resized, a thumbnail created, and both written to a server side directory.  I'm killing the path, not sure if it's relative or needs to be absolute.  The new field (multimedia) isn't getting populated at all.  In the 11th hour (of course).  Can you help?

 

foreach($files['userfile']['name'] as $key=>$value){

        if(!empty($files['userfile']['name'][$key])){

 

            $upload_dir = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

            $id=substr($data['id'],strspn($data['id'], "0"));

            $value = $id.".".$key.substr($value,strrpos($value,"."));

            $upload_file = $upload_dir.$value;

            $media_path = 'images/talent/'.$value;

            $original = $files['userfile']['tmp_name'][$key];

 

            if(file_exists($upload_file)){

             

              $select="SELECT media_id FROM multimedia WHERE media_path='".$media_path."'";

              $res=mysql_query($select);

              $val=mysql_fetch_assoc($res);

             

              $query3 = "UPDATE multimedia

                          SET media_path='".$media_path."',

                              media_type='".$files['userfile']['type'][$key]."'

                          WHERE media_id=".$val['media_id']." AND tlnt_id=".$data['id'];

            }

            else{

 

              $query3 = "INSERT INTO multimedia

                          VALUES(NULL,'".$data['id']."','".$media_path."','".$files['userfile']['type'][$key]."')";

            }

 

            $copy=copy($original, $upload_file);

            if($copy==="false"){

              echo "Copy file failed";

              return false;

            }

 

            if($key==0){

              $src_img=imagecreatefromjpeg($original);

              $origw=imagesx($src_img);

              $origh=imagesy($src_img);             

             

              if($origh > 150){

                  $new_h = 150;

                  $new_w=$origw*150/$origh;

              }

              else{

                  $new_h=$origh;

                  $new_w=$origw;

              }

              $dst_img = imagecreatetruecolor($new_w,$new_h);

              imagecopyresampled($dst_img,$src_img,0,0,0,0,$new_w,$new_h,$origw,$origh);

              $cp_this=$upload_dir."thumb_".$value;

              imagejpeg($dst_img,$cp_this);

            }

           

            $result = mysql_query($query3);

 

            if(!$result){

              print_r($_FILES);

              echo "Media update query failed:  $query3<br />";

              return false;

            }

        }

      }

      return true;

  }

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.