//// index.php
///////////////////////////////////////////////////////////////////////////////////////////////////
<script>
function displayfun(){
var imgno=document.getElementById('imgno').value;
for(var i=1; i<=imgno; i++){
var display=display+'<br><input type=file name=phot_'+i+' name=phot_'+i+'>';
document.getElementById('displayarea').innerHTML=display;
}
}
</script>
<form name="f1" action="<?php $_SERVER['URI_REQUEST'];?>" enctype="multipart/form-data" method="post">
<input type="text" name="imgno" id="imgno" />
<input type="button" value="Create Upload Button" onclick="displayfun()"/>
<span id="displayarea"></span>
<input type="submit" name="sub" value="Enter" />
</form>
<?php
if(isset($_REQUEST['sub']))
{
$path='uploaded/';
$imgno=$_REQUEST['imgno'];
for($i=1; $i<=$imgno; $i++){
if(move_uploaded_file($_FILES['phot_'.$i]['tmp_name'],$path.$_FILES['phot_'.$i]['name'])){
$sourcePath = 'uploaded/';
$sourceName = $_FILES['phot_'.$i]['name'];
$thumbPath = $sourcePath . 'thumbs/';
$thumbName = $sourceName;
$thumbWidth = 60;
$sourceImage = imagecreatefromjpeg("$sourcePath/$sourceName");
$sourceWidth = imagesx($sourceImage);
$sourceHeight = imagesy($sourceImage);
$targetImage = imagecreate($thumbWidth,$thumbWidth);
imagecopyresized($targetImage,$sourceImage,0,0,0,0,$thumbWidth,
$thumbWidth,imagesx($sourceImage),imagesy($sourceImage));
imagejpeg($targetImage, "$thumbPath/$thumbName");
echo "Image uploaded and thumb created successfully";
?>
<img src="uploaded/<?php echo $_FILES['phot_'.$i]['name'] ;?>" >
<br>
<?php
}
else{
echo "Failed to upload file and create thumb";
}
}
}
?>
//// End index.php
///////////////////////////////////////////////////////////////////////////////////////////////////
No comments:
Post a Comment