Jump to content

Forms in array Help


clanstyles

Recommended Posts

I have:

 

if ($_FILES['image']['type'] == "image/gif" || $_FILES['image']['type'] == "image/jpg" || $_FILES['image']['type'] == "image/jpeg")
                            				{
                            					$ran[0] = rand(1, 9999);
                            					$ran[1] = rand(1, 9999);
                            					if(isset($_REQUEST['image']) == 0)
                            					{
                            						copy ($_FILES['image']['tmp_name'], "uploadedimages/".$ran[0].$ran[1].$_FILES['image']['name']) or die ("Could not upload image #1."); 
                            					}
                            					if(isset($_REQUEST['image']) == 1)
                            					{
                            						copy ($_FILES['image']['tmp_name'], "uploadedimages/".$ran[0].$ran[1].$_FILES['image']['name']) or die ("Could not upload image #1."); 
                            					}
                            					if(isset($_REQUEST['image']) == 2)
                            					{
                            						copy ($_FILES['image']['tmp_name'], "uploadedimages/".$ran[0].$ran[1].$_FILES['image']['name']) or die ("Could not upload image #1."); 
                            					}
                            					echo count($_REQUEST['image']);
                            					echo $_REQUEST['image'];
                            					$str = implode("|", $_REQUEST['image']);
                            					echo $str;

I'm trying to upload 3 image and then implde them in | style. Later I can expode it and shhow them blah have that done easy. This is hard for me. Ican't use foreach statements.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/57782-forms-in-array-help/
Share on other sites

your method's seem wack.  This is my script for uploading X images.  I also included the form

<html>
<form name='FORMNAME' action='ACTION' method='post' enctype='multipart/form-data'>
<input type='hidden' name='newimages' value='yes' />
<input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
<br/>
<input type="file" name="imagefile0"/><br/>
<input type="file" name="imagefile1"/><br/>
<input type="file" name="imagefile2"/><br/>
<input type="file" name="imagefile3"/><br/>
//Append to the inputs for the number of images you need.
</html>

 

This is the part of the process page that handles these images

<?php
//Lets add some nubmers for safety
$random_digit = $_POST['random'];  (can be loaded here, but I have the option to reupload images so this way they don't use new numbers
$us = "_";
$pathto = "/files/".$random_digit.$us;  //stores the image in the folder files/randomnumber_
$i = 0;
while ($i <= 3)  //Handles 4 images selfexplainotory
{
if ($_FILES['imagefile'.$i]['type'] == "image/jpeg" || $_FILES['imagefile'.$i]['type'] == "image/jpg"
	 || $_FILES['imagefile'.$i]['type'] == "image/pjpeg" || $_FILES['imagefile'.$i]['type'] == "image/pjpg"){
	$count++;
	$file_name = "";
	$file_name .= "temp.";
	$file_name .= str_replace(".jpg","",str_replace("/","",str_replace("image","",$_FILES['imagefile'.$i]['type'])));  //Replaces to lowercase only .jpg files
	$ext = ".jpg";
	//Lets make a new name
	$new_file_name=$random_digit.$us.$count.$ext;
	//Lets Path it
	$path[$count]= "files/".$new_file_name;
	if(copy($_FILES['imagefile'.$i]['tmp_name'], $path[$count])){
		echo "It Copied!!!<br/>";
	}
	else{
		echo "copy Failed<br/>";
	}

}
$i++;
}
?>

Link to comment
https://forums.phpfreaks.com/topic/57782-forms-in-array-help/#findComment-286240
Share on other sites

not working :( It can't get past the iamge type..

			while ($i < 3)  //Handles 4 images selfexplainotory
										{
											if ($_FILES['image'.$i]['type'] == "image/jpeg" || $_FILES['image'.$i]['type'] == "image/jpg"
												 || $_FILES['image'.$i]['type'] == "image/pjpeg" || $_FILES['image'.$i]['type'] == "image/pjpg"){
												$count++;
												$file_name = "";
												$file_name .= "temp.";
												$file_name .= str_replace(".jpg","",str_replace("/","",str_replace("image","",$_FILES['imagefile'.$i]['type'])));  //Replaces to lowercase only .jpg files
												$ext = ".jpg";
												//Lets make a new name
												$new_file_name=$random_digit.$us.$count.$ext;
												//Lets Path it
												$path[$count]= "uploadedimages/".$new_file_name;
												if(copy($_FILES['imagefile'.$i]['tmp_name'], $path[$count])){
													echo "It Copied!!!<br/>";
												}
												else{
													echo "copy Failed<br/>";
												}

											}
											else {
												echo "You have a bad image type.";
											}

 

									echo "     <td ><label>(Optinal) Image #1:</label></td>";
									echo "      <td ><input type=\"file\" name=\"image1\"></td>";
									echo "    </tr>";
									echo "    <tr>";
									echo "     <td ><label>(Optinal) Image #2:</label></td>";
									echo "      <td ><input type=\"file\" name=\"image2\"></td>";
									echo "    </tr>";
									echo "    <tr>";
									echo "     <td ><label>(Optinal) Image #3:</label></td>";
									echo "      <td ><input type=\"file\" name=\"image3\"></td>";
									echo "    </tr>";
									echo "    <tr>";

Link to comment
https://forums.phpfreaks.com/topic/57782-forms-in-array-help/#findComment-286254
Share on other sites

8 digit random is sufficent , but it should be working make sure the folder is all right.  Secondly you should develop your own naming system so that its in a format of your liking (and handles all extensions) should make it all lowercase anyway which is easier to do than what I did.  This is only code I just haven't updated in a year or so

Link to comment
https://forums.phpfreaks.com/topic/57782-forms-in-array-help/#findComment-286285
Share on other sites

no need my system was naming them

 

temp_$randomnumber_$imgnumber.$extension

 

so you can recall them from $randomnumber  I don't even understand that sentence implode with a | between each name.  You are naming each file individually not together so why you need that?

 

Link to comment
https://forums.phpfreaks.com/topic/57782-forms-in-array-help/#findComment-286289
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.