dropfaith Posted September 3, 2008 Share Posted September 3, 2008 this script uploads all the images properly as i need the only issue im having is down at the bottom on the insert its only getting the image name for one image..no idea whats wrong it uploads multipul my server but wont get the names any ideas? <?php // images dir - relative from document root // this needs to be a folder that is writeable by the server $image_dir = '/test/images/'; // upload dir $destination = $_SERVER['DOCUMENT_ROOT'].$image_dir; if(isset($_FILES)) { // initialize error var for processing $error = array(); // acceptable files // if array is blank then all file types will be accepted $filetypes = array( 'gif' => 'image/gif', 'jpg' => 'image/jpeg', 'jpe' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'tif' => 'image/tiff', 'tiff' => 'image/tiff', ); // function to check for accpetable file type function okFileType($type) { // if filetypes array is empty then let everything through if(count($GLOBALS['filetypes']) < 1) { return true; } // if no match is made to a valid file types array then kick it back elseif(!in_array($type,$GLOBALS['filetypes'])) { $GLOBALS['error'][] = $type.' is not an acceptable file type. '. $type.' has been ignored.'; return false; } // else - let the file through else { return true; } } // function to check and move file function processFile($file) { // set full path/name of file to be moved $upload_file = $GLOBALS['destination'].$file['name']; if(file_exists($upload_file)) { $GLOBALS['error'][] = $file['name'].' - Filename exists - please change your image filename'; return false; } if(!move_uploaded_file($file['tmp_name'], $upload_file)) { // failed to move file $GLOBALS['error'][] = 'File Upload Failed on '.$file['name'].' - Please try again'; return false; } else { // upload OK - change file permissions chmod($upload_file, 0755); return true; } } // check to make sure files were uploaded $no_files = 0; $uploaded = array(); foreach($_FILES as $file) { switch($file['error']) { case 0: // file found if($file['name'] != NULL && okFileType($file['type']) != false) { // process the file if(processFile($file) == true) $uploaded = $file['name']; } break; case (1|2): // upload too large $error[] = 'file upload is too large for '.$file['name']; break; case 4: // no file uploaded break; case (6|7): // no temp folder or failed write - server config errors $error[] = 'internal error - flog the webmaster on '.$file['name']; break; } } } include 'template/conf.php'; // open database connection $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); // select database mysql_select_db($db) or die ("Unable to select database!"); echo "<hr>"; $Title=$_POST['Title']; $Cat=$_POST['Cat']; $Photographer=$_POST['Photographer']; $Makeup=$_POST['Makeup']; $Hair=$_POST['Hair']; $Wardrobe=$_POST['Wardrobe']; if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); $filePath = addslashes($filePath); } $rt=mysql_query("insert into gallery (Title, Cat, Photographer, Makeup, Hair, Wardrobe, uploaded, destination) values('$Title','$Cat','$Photographer','$Makeup','$Hair','$Wardrobe','$uploaded','$destination')") or die(mysql_error()); ?> Link to comment https://forums.phpfreaks.com/topic/122633-php-uploads/ Share on other sites More sharing options...
dropfaith Posted September 3, 2008 Author Share Posted September 3, 2008 is my mysql table CREATE TABLE `gallery` ( `Id` int(5) NOT NULL auto_increment, `Title` varchar(250) NOT NULL, `Cat` varchar(250) NOT NULL, `Photographer` varchar(250) NOT NULL, `Makeup` varchar(250) NOT NULL, `Hair` varchar(250) NOT NULL, `Wardrobe` varchar(250) NOT NULL, `pcredit` varchar(250) NOT NULL, `mcredit` varchar(250) NOT NULL, `hcredit` varchar(250) NOT NULL, `wcredit` varchar(250) NOT NULL, `uploaded` varchar(64) NOT NULL, `destination` varchar(64) NOT NULL, PRIMARY KEY (`Id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=12 ; Link to comment https://forums.phpfreaks.com/topic/122633-php-uploads/#findComment-633204 Share on other sites More sharing options...
dropfaith Posted September 4, 2008 Author Share Posted September 4, 2008 anyone? Link to comment https://forums.phpfreaks.com/topic/122633-php-uploads/#findComment-633274 Share on other sites More sharing options...
richardw Posted September 4, 2008 Share Posted September 4, 2008 Try this: $arraynum = sizeof($uploaded); //how many entities the array contains //then use for each to loop through the insert statement up for x number of files uploaded insert into gallery (Title, Cat, Photographer, Makeup, Hair, Wardrobe, uploaded, destination) values('$Title'[$i],'$Cat[$i]','$Photographer'[$i],'$Makeup'[$i],'$Hair'[$i],'$Wardrobe'[$i],'$uploaded'[$i],'$destination[$i]')"; Link to comment https://forums.phpfreaks.com/topic/122633-php-uploads/#findComment-633306 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.