ecstatica Posted August 14, 2008 Share Posted August 14, 2008 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; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.