Jump to content

PHP Image Upload


ashton321

Recommended Posts

Hello,

 

I am working on a multiple image upload script.  I have it working but at the moment i need to call the page from a form that posts the number of fields to display.  To change this after I need to reload the page.  What I would like to do is add a button that adds another input to the bottom of the form without losing anything that has already been entered.  Thanks for any help.

 

Here is what I have that deals only with the upload without much validation yet.

<?php
if($_GET['action'] == 'upload')
{
	while(list($key,$value) = each($_FILES['images']['name'])){
		if(!empty($value))
		{
			$filename = $value;
				$filename=str_replace(" ","_",$filename);
				$add = "images/house/$filename";
				copy($_FILES['images']['tmp_name'][$key], $add);
				chmod("$add",0777);
		}
	}
}
else
{
	include('inc/config.php');
	include('inc/functions.php');

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Design by Free CSS Templates
http://www.freecsstemplates.org
Released for free under a Creative Commons Attribution 2.5 License
-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title><?php printtitle();?></title>
<meta name="keywords" content="" />
<meta name="description" content="" />
</head>
<body>
<div id="header">
<?php include('inc/header.php'); ?>
</div>
<div id="content">
<div id="posts">
		<div class="post">
				<h2 class="title">Add Images</h2>
				<div class="meta">
				</div>					
				<div class="story">
					<form action="addimages.php?action=upload" enctype="multipart/form-data" method="post">
						<fieldset>
							<legend>Upload Images</legend>
							<?php
								$max_no_img = $_POST['numberOfImages'];
								for($i=1; $i<=$max_no_img; $i++){
								echo "<div>
										<label for='name'>Image $i:</label>
										<input name='images[]' type='input'/>
									</div>";
								}
							?>								
						</fieldset>
						<div class="submit">
							<input type="submit" value="SUBMIT" name="submit" id="submit" />
						</div>
					</form>
				</div>
		</div>
</div>
<div id="sidebar">
	<?php include('inc/sidebar.php'); ?>
</div>
</div>	
<div id="footer">
<?php include('inc/footer.php'); ?>
</div>
</body>
</html>
<?php
}
?>

Link to comment
https://forums.phpfreaks.com/topic/204955-php-image-upload/
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.