Ne0_Dev Posted March 9, 2010 Share Posted March 9, 2010 Hi, I have successfully implemented this class http://www.verot.net/home.htm to upload 6 images as per the examples given in the FAQ on this site and also storing the correct filename in my database table. My question relates to an update record page that I have, that allows for the changing of images associated with a record. As each image name is stored in a separate field in the table I am having difficulty updating the correct field with the correct image name. This I believe is down to the fact that not all images are being replaced and therefore the $_FILES array has empty records depending on which images were selected to be changed. I am using the values stored in the $uploaded array to store in the database. Having carried out some testing on the contents of the arrays during this process, I am still none the wiser so I am hoping that someone maybe able to point me in the right direction. Here is the code that I am using: //initialize new images to be uploaded $files = array(); foreach ($_FILES['image'] as $k => $l) { foreach ($l as $i => $v) { if (!array_key_exists($i, $files)) $files[$i] = array(); $files[$i][$k] = $v; } } // create an array here to hold file names $uploaded = array(); foreach ($files as $file) { $handle = new Upload($file); if ($handle->uploaded) { // create a little array for this set of pictures $this_upload = array(); $handle->file_safe_name = true; $handle->file_auto_rename = true; $handle->file_max_size = '512000'; $handle->allowed = array('image/jpeg', 'image/jpg'); $handle->Process($dir_dest); if ($handle->processed) { echo $handle->file_dst_name; // store the image filename $this_upload['image'] = $handle->file_dst_name; } else { echo 'error : ' . $handle->error; } // add this set of pictures to the main array $uploaded[] = $this_upload; } } Any help greatfully received. Ne0_Dev Link to comment https://forums.phpfreaks.com/topic/194606-multiple-image-upload-filenames/ Share on other sites More sharing options...
Ne0_Dev Posted March 10, 2010 Author Share Posted March 10, 2010 Hi All, I guess my request was a bit vague due to the lack of responses to my original post. Therefore I am hoping that by explaining my scenario a bit better someone might be able to point my in the right dirrection. I have an update page that has 6 images each with a check box to determine whether it is to be replaced during the update process. The problem I am having is that when the form is submitted and only a couple of the images are selected to be replaced, I am not able to keep track of the correct filename to insert into the table. I think it has something to do with this part of the code but I am not 100% sure. I am using the values stored in the $uploaded array to store in the database: //initialize new images to be uploaded $files = array(); foreach ($_FILES['image'] as $k => $l) { foreach ($l as $i => $v) { if (!array_key_exists($i, $files)) $files[$i] = array(); $files[$i][$k] = $v; } } // create an array here to hold file names $uploaded = array(); foreach ($files as $file) { $handle = new Upload($file); if ($handle->uploaded) { // create a little array for this set of pictures $this_upload = array(); $handle->file_safe_name = true; $handle->file_auto_rename = true; $handle->file_max_size = '512000'; $handle->allowed = array('image/jpeg', 'image/jpg'); $handle->Process($dir_dest); if ($handle->processed) { echo $handle->file_dst_name; // store the image filename $this_upload['image'] = $handle->file_dst_name; } else { echo 'error : ' . $handle->error; } // add this set of pictures to the main array $uploaded[] = $this_upload; } If someone could possibly give me some idea as to how to achieve this it would be most appreciated. Ne0_Dev Link to comment https://forums.phpfreaks.com/topic/194606-multiple-image-upload-filenames/#findComment-1024129 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.