Search
Left Quote    Nearly all men can stand adversity, but if you want to test a man's character, give him power.
- Abraham Lincoln    
Right Quote
 
[login] | [Register]
Forum Index » PHP and mySQL » Viewing Topic and Replies
Post Reply


        Viewing Topic: image upload in php
  This user is offline  sowmya
  Subject: "image upload in php" Posted: @ 11:42 am on Jan 27 2009   
Member #: 830
Rank: User - (4)
Since: 01/27/09
Posts: 4

hai friends,
can any one of you help me with coding an uploading of images into a specific folder.an image has to loaded with size <=1kb and height and width has to be of 250. once the image is loaded, the form has to display the uploaded images, their sizes, the location where it is stored, when the image was uploaded. download and delete links has to be there along with the images shown and when delete is clicked the image has to be deleted from the specified folder.
please help me out with this problem.
i am trying to my level best to get a solution for this, but i am in

    Viewed: 6,842 Times | Reply to This | To top
  This user is offline  bs0d
  Subject: "re: image upload in php" Posted: @ 1:03 pm on Jan 27 2009    

Member #: 1
Rank: Admin. - (1,505)
Since: 02/06/05
Posts: 600
From: USA

sowmya,

This article, Uploading Image Files with PHP should get you off to to a great start.

Once you learn how the script is working, displaying the image and stats as a confirmation after uploading should be no problem.

As far as deleting an image, you'll create a delete script, and pass to it the variables that identify the image you want to delete. You may want a members system so that only an 'admin' or the user of the image can delete images.

Hope all is well. Thanks,




-bs0d | AllSyntax.com

    Viewed: 6,792 Times | Reply to This | To top
  This user is offline  sowmya
  Subject: "re: image upload in php" Posted: @ 5:57 am on Jan 29 2009    
Member #: 830
Rank: User - (4)
Since: 01/27/09
Posts: 4

hai bs0d,
thanks for the articlke provided.
but it is used with mysql.i don't want to interact with database right now.is there any other solution for this without using database.
thanks for your help.
regards,
sowmya.



    Viewed: 6,765 Times | Reply to This | To top
  This user is offline  sowmya
  Subject: "re: image upload in php" Posted: @ 9:17 am on Jan 29 2009    
Member #: 830
Rank: User - (4)
Since: 01/27/09
Posts: 4

hai bs0d,
i have got a solution for this.
here is the code for the above program.

Code:


/*program named as uploadfile.php* /

<?php
$path="up loaded files/";/ /path where the uploaded images have to be saved
$today = date('dmYhms' );
$name=$_FILES[ 'upload']['na me'];
$fullpath=$path .$name;
$type=$_FILES[ 'upload']['ty pe'];
if ($_FILES['uplo adfile']['err or'] > 0)
{
echo "Error: " . $_FILES['uploa dfile']['erro r'] . "<br />";
}
else
{
if(($type!=& quot;image/jpeg " && ($ty pe!="imag e/gif" && ($ty pe!="imag e/png" || (($_FILES['upl oad']['size' ]>1024)))
{
echo "Either your file exceeds the limit or an invalid file";
}
else
{
echo "Upload: " .$_FILES['uplo ad']['name'] . "<br />";
echo "Type: " . $_FILES['uploa d']['type'] . "<br />";
echo "Size: " . ($_FILES['uplo ad']['size'] ) . " Bytes<br />";
echo "Stored as: " . $_FILES['uploa d']['name'];
move_uploaded_f ile($_FILES['u pload']['tmp_ name'],$fullpa th);
}
}

?>

<!DOCTYPE html PUBLIC "-//W3C// DTD XHTML 1.0 Transitional//E N" "http://w ww.w3.org/TR/xh tml1/DTD/xhtml1 -transitional.d td">
<html xmlns="ht tp://www.w3.org /1999/xhtml&qu ot;>
<head>
<meta http-equiv=&qu ot;Content-Type " content=" text/html; charset=iso-885 9-1" />
<title>Up loading a file</title& gt;
</head>

<body>
<form method="p ost" action="u ploadfile.php& quot; enctype=" multipart/form- data">
<input type="fil e" name="upl oad" />
<input type="sub mit" value="Up load" name="upl oad" />
</form>
<?php if(is_dir($path ))
{
if($open=opend ir($path))
{
while(($file []=readdir($ope n))!==false)
{} ?>

<table width="10 0%" border="0 ">
<tr>
<td>File Name</td>
<td>Type& lt;/td>
<td>Size& lt;/td>
<td>Thum b Nail</td>
<td>Dimen sion</td>
<td>Downl oad</td>
<td>Delet e</td>
</tr>
<?php foreach($file as $val)
{
if(($val!=&quo t;." && ($val!=". ." && ($val!="T humbs.db"< img src=http://www. allsyntax.com/f orums/images/sm ilies/wink.gif border=0>&& amp;($val!=&qu ot;")
{
?>
<tr>
<td><? php echo $val; ?></td> ;
<td><? php $ext=pathinfo($ val); echo $ext['extensio n']; ?></td> ;
<td><? php $size= round(filesize( $path.$val)/102 4); echo $size."KB "; ?></td> ;
<td>< img src="< ?php echo $path.$val; ?>" style="wi dth:30px;height :30px;" /></td> ;
<td><? php $dim = getimagesize($p ath.$val); echo $dim[0]." x ".$dim[1] ; ?></td> ;
<td><a href="dow nload.php?file= <?php echo $val; ?>"> ;Download</a ></td>
<td><a href="del ete.php?file=&l t;?php echo $val; ?>"> ;Delete</a&g t;</td>
</tr>
<?php
}
}
}
closedir($open );
} ?>
</table>
</body>
</html>

/*program delete.php*/

<?php
$file = $_GET['file'] ;
global $uploaddir;
$uploaddir=&q uot;uploaded files/";
$path = $uploaddir;
deleteFile($pa th,$file);
function deleteFile($pat h,$file)
{
if(file_exist s($path.$file))
{unlink($path .$file);}
header(" ;Location:uploa dfile.php" ;
}

?>





Edited at 12:49:06 pm on 01/29/09


    Viewed: 6,756 Times | Reply to This | To top
Viewing Page: 1 of 1


1 |

You must be logged in to post on the forums. Login or Register








"AllSyntax.com" Copyright © 2002-2018; All rights lefted, all lefts righted.
Privacy Policy  |  Internet Rank