piznac Posted October 26, 2006 Share Posted October 26, 2006 Ok got a strange one here:[code]require_once('/home/rack/public_html/project/Connections/pms.php'); //get job number$job = $_POST['num'];//get directory$direc = $_POST['nam'];//change spaces to _ for dir$dir1=trim($direc);$dir2=str_replace(' ', '_', $dir1);//set base path for database$basepath="http://project.rackattackzone.com/jobs/$dir2/return_images/";$thumbpath="http://project.rackattackzone.com/jobs/$dir2/return_images/thumbs/";//get array of filenamesforeach($_FILES['file']['name'] as $value1) {$filename .= "$value1";//change spaces to %20$filenames=trim($filename);$filenamea=str_replace(' ', '%20', $filename);}foreach ($_FILES['file']['name'] as $k => $filenamea) { if ($filenamea != '') { $tmpfile = $_FILES['file']['tmp_name'][$k]; } //if the temp file1 is there copy it to the server if (@is_uploaded_file($tmpfile) && $filenamea != '') { copy($tmpfile, "/home/rack/public_html/project/jobs/$dir2/return_images/" .$filename); }//get image size and nameif ($filename != ''){$im_file_name = "/home/rack/public_html/project/jobs/$dir2/return_images/" . $filename;$image_attribs = getimagesize($im_file_name); $im_old = imageCreateFromJpeg($im_file_name); //declare thumb$th_max_width = 100; $th_max_height = 100; $ratio = ($width > $height) ? $th_max_width/$image_attribs[0] : $th_max_height/$image_attribs[1]; $th_width = $image_attribs[0] * $ratio; $th_height = $image_attribs[1] * $ratio; $im_new = imagecreatetruecolor($th_width,$th_height); imageAntiAlias($im_new,true); //resize image$th_file_name = "/home/rack/public_html/project/jobs/$dir2/return_images/thumbs/" . $filename;imageCopyResampled($im_new,$im_old,0,0,0,0,$th_width,$th_height, $image_attribs[0], $image_attribs[1]); imageJpeg($im_new,$th_file_name,100); //get array of filenames$pathname = $basepath . $filenamea;$thumbpath2 = $thumbpath . $filenamea;if ($filenamea != ''){$mysql = "rack_pm";mysql_select_db($mysql);$sql = "INSERT INTO `returnedfiles` (`imagepath`, `thumbpath`, `jobnum`, `pname`, `num`, `autojobnum`) VALUES ('$pathname', '$thumbpath2', '$job', '$direc', NULL, '1');";mysql_query($sql) or die(mysql_error());}} }?> [/code] If one file is uploaded this works great. But if I upload multiple files,.. well its wierd it names 1 file with all the names of the other files. It only thumbnails one and the insert into database seems to work fine. So where did I go wrong? Also is thier a faster way of doing this? This is on a windows mobile enabled smart phone so speed is very important....thanks! Quote Link to comment Share on other sites More sharing options...
piznac Posted October 26, 2006 Author Share Posted October 26, 2006 bump :) Quote Link to comment Share on other sites More sharing options...
alpine Posted October 26, 2006 Share Posted October 26, 2006 On a quick glance, you are running two separate foreach loops, the first one will complete before the next one starts, leaving you with only the value of the last file uploaded (and yes - i notice the $filename .= but i dont understand your logic....)For a start, remove your first loop and include your trim and str_replace etc in the main loop. See what that brings. Quote Link to comment Share on other sites More sharing options...
piznac Posted October 26, 2006 Author Share Posted October 26, 2006 ok I'll give that a shot Quote Link to comment Share on other sites More sharing options...
piznac Posted October 26, 2006 Author Share Posted October 26, 2006 Wow,.. that seems to have fixed the problem,...[code]require_once('/home/rack/public_html/project/Connections/pms.php'); //get job number$job = $_POST['num'];//get directory$direc = $_POST['nam'];//change spaces to _ for dir$dir1=trim($direc);$dir2=str_replace(' ', '_', $dir1);//set base path for database$basepath="http://project.rackattackzone.com/jobs/$dir2/return_images/";$thumbpath="http://project.rackattackzone.com/jobs/$dir2/return_images/thumbs/";foreach ($_FILES['file']['name'] as $k => $filename) { if ($filename != '') { $tmpfile = $_FILES['file']['tmp_name'][$k]; } //change spaces to %20$filenames=trim($filename);$filenamea=str_replace(' ', '%20', $filenames); //if the temp file1 is there copy it to the server if (@is_uploaded_file($tmpfile) && $filenamea != '') { copy($tmpfile, "/home/rack/public_html/project/jobs/$dir2/return_images/" .$filename); }//get image size and nameif ($filename != ''){$im_file_name = "/home/rack/public_html/project/jobs/$dir2/return_images/" . $filename;$image_attribs = getimagesize($im_file_name); $im_old = imageCreateFromJpeg($im_file_name); //declare thumb$th_max_width = 100; $th_max_height = 100; $ratio = ($width > $height) ? $th_max_width/$image_attribs[0] : $th_max_height/$image_attribs[1]; $th_width = $image_attribs[0] * $ratio; $th_height = $image_attribs[1] * $ratio; $im_new = imagecreatetruecolor($th_width,$th_height); imageAntiAlias($im_new,true); //resize image$th_file_name = "/home/rack/public_html/project/jobs/$dir2/return_images/thumbs/" . $filename;imageCopyResampled($im_new,$im_old,0,0,0,0,$th_width,$th_height, $image_attribs[0], $image_attribs[1]); imageJpeg($im_new,$th_file_name,100); //get array of filenames$pathname = $basepath . $filenamea;$thumbpath2 = $thumbpath . $filenamea;if ($filenamea != ''){$mysql = "rack_pm";mysql_select_db($mysql);$sql = "INSERT INTO `returnedfiles` (`imagepath`, `thumbpath`, `jobnum`, `pname`, `num`, `autojobnum`) VALUES ('$pathname', '$thumbpath2', '$job', '$direc', NULL, '1');";mysql_query($sql) or die(mysql_error());}} }?> [/code] Thanks man 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.