Jump to content

Upload image resize on multiple files


cdoggg94

Recommended Posts

Basically what I want to know is if its possible to take this upload code:

 

<?php
set_time_limit(0);
require_once("Connections/myConnect.php");
mysql_select_db("phpmy1_norfolkartscentre_ca");
$preName = $_POST['name'];
$preText = $_POST['text'];
$preLink = $_POST['links'];


if(isset($_FILES['picture'])){
foreach($_FILES['picture']['tmp_name'] as $key => $tmp_name){
	move_uploaded_file($tmp_name, "data/{$_FILES['picture']['name'][$key]}");
	}
	//print_r($_FILES);
	$pre_banner = $_FILES['picture']['name'][0];
	$pre_logo1  = $_FILES['picture']['name'][1];
	$pre_logo2  = $_FILES['picture']['name'][2];
	$pre_logo3  = $_FILES['picture']['name'][3];
	$pre_scale1  = $_FILES['picture']['name'][4];
	$pre_scale2  = $_FILES['picture']['name'][5];
	$pre_scale3  = $_FILES['picture']['name'][6];
	$pre_scale4  = $_FILES['picture']['name'][7];
	$pre_scale5  = $_FILES['picture']['name'][8];
	$pre_scale6  = $_FILES['picture']['name'][9];
	$pre_scale7  = $_FILES['picture']['name'][10];
	$pre_scale8  = $_FILES['picture']['name'][11];
	$pre_scale9  = $_FILES['picture']['name'][12];

			$querystring = "INSERT INTO presentation_tbl(pre_id,pre_name,pre_banner,pre_text,pre_link,pre_logo1,pre_logo2,pre_logo3,scale_1,scale_2,scale_3,scale_4,scale_5,scale_6,scale_7,scale_8,scale_9) VALUES(NULL,'".$preName."','".$pre_banner."','".$preText."','".$preLink."','".$pre_logo1."','".$pre_logo2."','".$pre_logo3."','".$pre_scale1."','".$pre_scale2."','".$pre_scale3."','".$pre_scale4."','".$pre_scale5."','".$pre_scale6."','".$pre_scale7."','".$pre_scale8."','".$pre_scale9."')";
$doquery = mysql_query($querystring);
echo "";
}else{
	echo "there was a problem uploading, please try again!";

}

 

and make it do (for each file..) what this code:

 

if(!isset($picture))
echo "";
	else
	{
	$image = addslashes(file_get_contents($_FILES['image']['tmp_name']));	
	$image_name = addslashes($_FILES['image']['name']);
	$image_size = getimagesize($_FILES['image']['tmp_name']);

	$max_width = 250;
$max_height = 377;
list($width, $height) = $image_size;
//echo $width.",".$height;
$ratioh = $max_height/$height;
$ratiow = $max_width/$width;
$ratio = min($ratioh, $ratiow);
// New dimensions
$mywidth = intval($ratio*$width);
$myheight = intval($ratio*$height);

 

does for one file

Link to comment
Share on other sites

So this is kind of what I have:

if(isset($_FILES['picture'])){
foreach($_FILES['picture']['tmp_name'] as $key => $tmp_name){

	$image = addslashes(file_get_contents($_FILES['picture']['tmp_name']));	
	$image_name = addslashes($_FILES['image']['name']);
	$image_size = getimagesize($_FILES['image']['tmp_name']);

	$max_width = 250;
	$max_height = 377;
	list($width, $height) = $image_size;
	//echo $width.",".$height;
	$ratioh = $max_height/$height;
	$ratiow = $max_width/$width;
	$ratio = min($ratioh, $ratiow);
	// New dimensions
	$mywidth = intval($ratio*$width);
	$myheight = intval($ratio*$height);

	move_uploaded_file($tmp_name, "data/{$_FILES['picture']['name'][$key]}");
	}
	print_r($_FILES)." ".$ratio."\r\n";

	$pre_banner = $_FILES['picture']['name'][0];
	$pre_bannerH =  ;
	$pre_bannerW =  ;
	$pre_logo1  = $_FILES['picture']['name'][1];
	$pre_logo2  = $_FILES['picture']['name'][2];
	$pre_logo3  = $_FILES['picture']['name'][3];
	$pre_scale1  = $_FILES['picture']['name'][4];
	$pre_scale2  = $_FILES['picture']['name'][5];
	$pre_scale3  = $_FILES['picture']['name'][6];
	$pre_scale4  = $_FILES['picture']['name'][7];
	$pre_scale5  = $_FILES['picture']['name'][8];
	$pre_scale6  = $_FILES['picture']['name'][9];
	$pre_scale7  = $_FILES['picture']['name'][10];
	$pre_scale8  = $_FILES['picture']['name'][11];
	$pre_scale9  = $_FILES['picture']['name'][12];

 

It does appear to print the sizes on the images that have been uploaded.

 

But how do i get the content for the: $pre_bannerH =  ; and $pre_bannerW =  ;  variables?

 

Would it be something like: $pre_bannerH = $myheight[0];

 

?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.