cyrixware Posted April 14, 2007 Share Posted April 14, 2007 Hi, is ther any idea how to upload jpg images. Let say for exmple, I have a text box and browse button.After i click the button that says upload the image will upload. Then when i click the button view the images will view. How can i do that? I need your help... pls send me a codes for that... And also i have a question uhmm... where is that images save? is ther a folder that all images will save or the images will save on the dbase? Regards, - Cyrixware Quote Link to comment Share on other sites More sharing options...
monkeymade Posted April 14, 2007 Share Posted April 14, 2007 html form: <form method="POST" enctype="multipart/form-data" action="playwith.php"> <p> <input type="file" name="userfile" size="20"> <input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"> </p> </form> PHP handler <?php $filesize = $_FILES['userfile']['size']; $filetype = $_FILES['userfile']['type']; $nameuse = filename; IF (($filesize <= 102000) AND ($filetype == 'image/pjpeg') OR ($filetype == 'image/jpeg')) { $nameuse = "$nameuse.jpg"; // In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead // of $_FILES. $uploaddir = '/home/yoursection/public_html/uploads/'; $uploadfile = $uploaddir . $nameuse; echo '<pre>'; if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) { echo "File is valid, and was successfully uploaded.\n"; } else { echo "Possible file upload attack!"; } } IF (($filetype != 'image/pjpeg') AND ($filetype != 'image/jpeg')) { echo "Your Image is the wrong file type, it must be a jpg image<BR>your image is $filetype"; } IF ($filesize > 102000) { echo "Your Image is to large to upload"; } ?> Quote Link to comment Share on other sites More sharing options...
cyrixware Posted April 14, 2007 Author Share Posted April 14, 2007 thanks for the reply... should i create a single image folder directory for the locations of the images uploaded? or should i creat this directory? $uploaddir = '/home/yoursection/public_html/uploads/'; i use localhost in my pc... ex: http://localhost/uploads/playwith.php then uploads folder : http://localhost/uploads/uploads Quote Link to comment Share on other sites More sharing options...
cyrixware Posted April 14, 2007 Author Share Posted April 14, 2007 ok i get it now.. the problem is that when i try to upload another image again the previous image deleted itself automatically... meaning in a sigle folder only 1 image can be stored.. how can i store more than a single image? thanks again Regards, Cyrix html form: <form method="POST" enctype="multipart/form-data" action="playwith.php"> <p> <input type="file" name="userfile" size="20"> <input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"> </p> </form> PHP handler <?php $filesize = $_FILES['userfile']['size']; $filetype = $_FILES['userfile']['type']; $nameuse = filename; IF (($filesize <= 102000) AND ($filetype == 'image/pjpeg') OR ($filetype == 'image/jpeg')) { $nameuse = "$nameuse.jpg"; // In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead // of $_FILES. $uploaddir = '/home/yoursection/public_html/uploads/'; $uploadfile = $uploaddir . $nameuse; echo '<pre>'; if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) { echo "File is valid, and was successfully uploaded.\n"; } else { echo "Possible file upload attack!"; } } IF (($filetype != 'image/pjpeg') AND ($filetype != 'image/jpeg')) { echo "Your Image is the wrong file type, it must be a jpg image<BR>your image is $filetype"; } IF ($filesize > 102000) { echo "Your Image is to large to upload"; } ?> Quote Link to comment Share on other sites More sharing options...
HeyRay2 Posted April 14, 2007 Share Posted April 14, 2007 Change this line of code: $nameuse = filename; ... to ... $nameuse = $_FILES['userfile']['name']; ... and that will stop your previous file from being overwritten. With the code the way it was, it was always naming the file "filename". Quote Link to comment Share on other sites More sharing options...
monkeymade Posted April 14, 2007 Share Posted April 14, 2007 as Heyray said, you want to change that line, but, if you have random people uploading its possible for them to overwrite each others files when they upload... the way I have it on my actual page is I use a timestamp basically for the file name, looks like this $nameuse = gmdate("YmdHis"); This way, the only way you get two with the same name is if they are posted at the exact same second Quote Link to comment Share on other sites More sharing options...
cyrixware Posted April 16, 2007 Author Share Posted April 16, 2007 gotcha! I have a problem about deleting images. I created 2 folders, 1st the folder IMAGES wherein the actual size of the images uploaded stored here. The other folder named THUMB stored the images i set the size use for my thumbnails in picture gallery. The problem is that, i dont know how to delete the images both folders. Let say for example, im going to browse the image then when i click delete the image deleted automatically in both folders. (Both folders is the same filename of the images inside) thanks Quote Link to comment Share on other sites More sharing options...
cyrixware Posted April 16, 2007 Author Share Posted April 16, 2007 i dont know how to delete the images in both folders at the same time.. pls help em.. thanks Folders: 1. IMAGES: pic.jpg 2. THUMB : pic.jpg Im going to browse the image after that if im going to click delete the images pic.jpg in folder IMAGES and THUMBS deleted automatically. How can i do that? Quote Link to comment Share on other sites More sharing options...
crazysaint Posted April 16, 2007 Share Posted April 16, 2007 hi! i will also need some help on this,instead of storing the images in a folder, how can i store the images in the dbase, am using mysql. Quote Link to comment Share on other sites More sharing options...
cyrixware Posted April 17, 2007 Author Share Posted April 17, 2007 anybody...? Quote Link to comment Share on other sites More sharing options...
cyrixware Posted April 17, 2007 Author Share Posted April 17, 2007 (image database) try this link: http://www.spoono.com/php/tutorials/tutorial.php?id=42 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.