Zen Cart Logo
Forums / General Questions / Adding Multiple Images to Custom form To be sent to Admin Email

Adding Multiple Images to Custom form To be sent to Admin Email

Views: 7,070

Results 41 to 57 of 57
29 Jan 2015, 6:50 PM
#41
digitalshadow avatar

digitalshadow

Totally Zenned

Join Date:
Mar 2009
Posts:
616
Plugin Contributions:
0

Adding Multiple Images to Custom form To be sent to Admin Email

also as per the code created by GodfatherAntiques

$att_array = array();
	foreach($_FILES as $key => $file) {
  if (zen_not_null($_FILES[$key]['tmp_name'])) {
    if ($upload = new upload($key, DIR_FS_UPLOADS)) {
        $att_array[] = array('file' => $upload->destination . $upload->filename, 'name' => $upload->filename);
    }
  }
}

what would you do with your suggestion in the array?

29 Jan 2015, 6:56 PM
#42
digitalshadow avatar

digitalshadow

Totally Zenned

Join Date:
Mar 2009
Posts:
616
Plugin Contributions:
0

Re: Adding Multiple Images to Custom form To be sent to Admin Email

if i wanted to append something to the end of

$var->set_destination=DIR_FS_UPLOADS; 

would this be right?

$folder = 'test/';

$var->set_destination=DIR_FS_UPLOADS . $folder; 

would that create

images/uploads/test/?

or

$folder = DIR_FS_UPLOADS;
$subfolder = 'test/';

$var->set_destination=($folder . $subfolder); 
29 Jan 2015, 7:09 PM
#43
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Adding Multiple Images to Custom form To be sent to Admin Email

yes, you can alter the folder with set_destination

29 Jan 2015, 7:43 PM
#44
digitalshadow avatar

digitalshadow

Totally Zenned

Join Date:
Mar 2009
Posts:
616
Plugin Contributions:
0

Re: Adding Multiple Images to Custom form To be sent to Admin Email

is this right to modify the filename??

$att_array = array();
	foreach($_FILES as $key => $file) {

	$fileorig = basename($_FILES['uploaded_file']['name']); 
        $newname = 'test';
        $filename = $newname.$fileorig;

  if (zen_not_null($_FILES[$key]['tmp_name'])) {
    $upload = new upload;
    $upload->set_file = $key;
    $upload->set_destination=DIR_FS_UPLOADS;
       if ($upload->parse() == true) {
    $upload->set_filename($filename); 
    $upload->save();
      } else {
           //die('could not manage uploads');
      }
        $att_array[] = array('file' => $upload->destination . $upload->filename, 'name' => $upload->filename);
    }
  }
}
29 Jan 2015, 7:53 PM
#45
digitalshadow avatar

digitalshadow

Totally Zenned

Join Date:
Mar 2009
Posts:
616
Plugin Contributions:
0

Re: Adding Multiple Images to Custom form To be sent to Admin Email

ok to modify the folder name, is now working...

$att_array = array();
	foreach($_FILES as $key => $file) {
	$folderid = 'test/';
	$imagefolder = DIR_FS_UPLOADS;
	$folderPath = $imagefolder . $folderid;
	$exist = is_dir($folderPath);
	if(!$exist) {
		mkdir("$folderPath");
		chmod("$folderPath", 0755);
	}
	else { echo "Folder already exists"; }
  if (zen_not_null($_FILES[$key]['tmp_name'])) {
    if ($upload = new upload($key, $folderPath)) {
        $att_array[] = array('file' => $upload->destination . $upload->filename, 'name' => $upload->filename);
    }
  }
}
29 Jan 2015, 11:17 PM
#46
digitalshadow avatar

digitalshadow

Totally Zenned

Join Date:
Mar 2009
Posts:
616
Plugin Contributions:
0

Re: Adding Multiple Images to Custom form To be sent to Admin Email

How could I modify the code in the above post to enable me to set the filename to be the current filename with a value at the beginning. I'm needing to get around the fact ios labels all its files for multiple file uploading as image.jpg, if I could put a random string before the filename that should solve the problem.

I've found examples of how to add a random value, but the array is confusing me, help please.

30 Jan 2015, 2:39 AM
#47
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Adding Multiple Images to Custom form To be sent to Admin Email

The code I gave you already lets you set the filename.

But, your confusion about "the array" is because the example I gave you was an example, and not necessarily a direct copy-and-paste because I didn't have your code to build it on. Mine used $var as the variable for interacting with the upload class. It appears as though you want to use $upload for yours, so replace all the $var in my example with $upload if you want your att_array to pick up the changes and pass them on to other parts of the code.

30 Jan 2015, 8:15 AM
#48
digitalshadow avatar

digitalshadow

Totally Zenned

Join Date:
Mar 2009
Posts:
616
Plugin Contributions:
0

Re: Adding Multiple Images to Custom form To be sent to Admin Email

Yes I assumed $var would be $upload
Does your example sit before the array section?

Essentially replacing the content of the if statement in brackets?

30 Jan 2015, 11:40 AM
#49
digitalshadow avatar

digitalshadow

Totally Zenned

Join Date:
Mar 2009
Posts:
616
Plugin Contributions:
0

Re: Adding Multiple Images to Custom form To be sent to Admin Email

this is the current code

$att_array = array();
	foreach($_FILES as $key => $file) {
	$folderid = 'test/';
	$imagefolder = DIR_FS_UPLOADS;
	$folderPath = $imagefolder . $folderid;
  if (zen_not_null($_FILES[$key]['tmp_name'])) {
	$exist = is_dir($folderPath);
	if(!$exist) {
		mkdir("$folderPath");
		chmod("$folderPath", 0755);
	}
    if ($upload = new upload($key, $folderPath)) {
        $att_array[] = array('file' => $upload->destination . $upload->filename, 'name' => $upload->filename);
    }
  }
}

is this right to modify the name, obviously i would need to define $filename

$att_array = array();
	foreach($_FILES as $key => $file) {
	$folderid = 'test/';
	$imagefolder = DIR_FS_UPLOADS;
	$folderPath = $imagefolder . $folderid;
  if (zen_not_null($_FILES[$key]['tmp_name'])) {
	$exist = is_dir($folderPath);
	if(!$exist) {
		mkdir("$folderPath");
		chmod("$folderPath", 0755);
	}
    if (    $upload = new upload;
    $upload->set_file = $key;
    $upload->set_destination=DIR_FS_UPLOADS;
       if ($upload->parse() == true) {
    $upload->set_filename($filename); 
    $upload->save();
      } else {
           //die('could not manage uploads');
      }) {
        $att_array[] = array('file' => $upload->destination . $upload->filename, 'name' => $upload->filename);
    }
  }
}
30 Jan 2015, 2:56 PM
#50
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Adding Multiple Images to Custom form To be sent to Admin Email

I would think it's better to move the $att_array[] = array(.....) up to the line between the $upload->save() and the else.

What has been the result of your testing your changes?

4 Feb 2015, 10:50 AM
#51
digitalshadow avatar

digitalshadow

Totally Zenned

Join Date:
Mar 2009
Posts:
616
Plugin Contributions:
0

Re: Adding Multiple Images to Custom form To be sent to Admin Email

would

$file_name = $_FILES[$key]['name'];

get me the name of the uploaded file?

4 Feb 2015, 11:05 AM
#52
digitalshadow avatar

digitalshadow

Totally Zenned

Join Date:
Mar 2009
Posts:
616
Plugin Contributions:
0

Re: Adding Multiple Images to Custom form To be sent to Admin Email

        $name_pre = 'test';
        $file_name = $_FILES[$key]['name'];  
	$file_ext = basename($_FILES[$key]['name']); 
	$ext = substr($file_ext, strrpos($file_ext, '.') + 1);

my question is, if I add something to the beggining of $file_name do i need to re add the extension or would it still retain the extension?

    ```php

$filename = $name_pre . $file_name;


would that work, or would I have to put the extension back on the end?
4 Feb 2015, 11:50 AM
#53
digitalshadow avatar

digitalshadow

Totally Zenned

Join Date:
Mar 2009
Posts:
616
Plugin Contributions:
0

Re: Adding Multiple Images to Custom form To be sent to Admin Email

this doesn't work Warning: no file uploaded.

$att_array = array();
	foreach($_FILES as $key => $file) {
	$folderid = 'test';
	$imagefolder = DIR_FS_UPLOADS;
	$folderPath = $imagefolder . $folderid;
	$name_pre = 'test';
        $file_name = ($_FILES[$key]['name']);  
	$file_ext = basename($_FILES[$key]['name']); 
	$ext = substr($file_ext, strrpos($file_ext, '.') + 1);
	$filename = 'test';  
  if (zen_not_null($_FILES[$key]['tmp_name'])) {
	$exist = is_dir($folderPath);
	if(!$exist) {
		mkdir("$folderPath");
		chmod("$folderPath", 0755);
	}
	 $upload = new upload; 
   	 $upload->set_file = $key;
 	 $upload->set_destination = $folderPath;
	if ($upload->parse() == true) { 
   	 $upload->set_filename = $filename; 
	 $att_array[] = array('file' => $upload->destination . $upload->filename, 'name' => $upload->filename);
  	 $upload->save();
    } else {
  //die('could not manage uploads');
}
  }
}
4 Feb 2015, 6:08 PM
#54
digitalshadow avatar

digitalshadow

Totally Zenned

Join Date:
Mar 2009
Posts:
616
Plugin Contributions:
0

Re: Adding Multiple Images to Custom form To be sent to Admin Email

it is uploading, but it is uploading to the root directory

4 Feb 2015, 6:20 PM
#55
digitalshadow avatar

digitalshadow

Totally Zenned

Join Date:
Mar 2009
Posts:
616
Plugin Contributions:
0

Re: Adding Multiple Images to Custom form To be sent to Admin Email

figured it out... silly me, will post new code shortly

4 Feb 2015, 6:36 PM
#56
digitalshadow avatar

digitalshadow

Totally Zenned

Join Date:
Mar 2009
Posts:
616
Plugin Contributions:
0

Re: Adding Multiple Images to Custom form To be sent to Admin Email

to enable file uploading from ios devices that name all files as image.jpg, i've set the image rename to be microtime as i was worried rand might clash, and then I would need a check for if the file already existed, this method seemed simpler.

$att_array = array();
    foreach($_FILES as $key => $file) {
    $folderid = 'test';
    $imagefolder = DIR_FS_UPLOADS;
    $folderPath = $imagefolder . $folderid;
    $name_pre = microtime();
    $file_name = ($_FILES[$key]['name']);  
    $file_ext = basename($_FILES[$key]['name']); 
    $ext = substr($file_ext, strrpos($file_ext, '.') + 1);
    $filename = ($name_pre . '.' . $ext);  
  if (zen_not_null($_FILES[$key]['tmp_name'])) {
    $exist = is_dir($folderPath);
    if(!$exist) {
        mkdir("$folderPath");
        chmod("$folderPath", 0755);
    }
     $upload = new upload; 
        $upload->set_file($key);
      $upload->set_destination($folderPath);
    if ($upload->parse() == true) { 
        $upload->set_filename($filename); 
       $upload->save();
     $att_array[] = array('file' => $upload->destination . $upload->filename, 'name' => $upload->filename);
    } else {
  //die('could not manage uploads');
}
  }
}  
27 Sep 2021, 8:59 PM
#57
chuckrey avatar

chuckrey

Zen Follower

Join Date:
Aug 2020
Location:
Richarson
Posts:
160
Plugin Contributions:
0

Re: Adding Multiple Images to Custom form To be sent to Admin Email

Wow, I realize it's been years since anyone has commented on this thread but I happen to come across it while searching for a way to create a form that will allow multiple images to be uploaded. Is this the latest and greatest thread for working to resolve this puzzle? Any input would be appreciated. I am currently using 1.5.7c.

Thanks in advance.:smile: