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
https://forums.phpfreaks.com/topic/119760-media_path-help-needed-desperately/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.