whiteboikyle Posted April 1, 2008 Share Posted April 1, 2008 Well i found this piece of code and i am trying to alter it and understand it.. <?php // Connect to database $errmsg = ""; if (! @mysql_connect("localhost","****","*****")) { $errmsg = "Cannot connect to database"; } @mysql_select_db("kazi"); // Insert any new image into database if ($_REQUEST[completed] == 1) { // Need to add - check for large upload. Otherwise the code // will just duplicate old file ;-) // ALSO - note that latest.img must be public write and in a // live appliaction should be in another (safe!) directory. move_uploaded_file($_FILES['imagefile']['tmp_name'],"latest.img"); $instr = fopen("latest.img","rb"); $image = addslashes(fread($instr,filesize("latest.img"))); if (strlen($instr) < 1500000) { mysql_query ("insert into pix (title, imgdata) values (\"". $_REQUEST[whatsit]. "\", \"". $image. "\")"); } else { $errmsg = "Too large!"; } } // Find out about latest image $gotten = @mysql_query("select * from pix order by pid desc limit 1"); if ($row = @mysql_fetch_assoc($gotten)) { $title = htmlspecialchars($row[title]); $bytes = $row[imgdata]; } else { $errmsg = "There is no image in the database yet"; $title = "no database image available"; // Put up a picture of our training centre $instr = fopen("../wellimg/ctco.jpg","rb"); $bytes = fread($instr,filesize("../wellimg/ctco.jpg")); } // If this is the image request, send out the image if ($_REQUEST[gim] == 1) { header("Content-type: image/jpeg"); print $bytes; exit (); } ?> <html><head> <title>Upload an image to a database</title> <body bgcolor=white><h2>Here's the latest picture</h2> <font color=red><?= $errmsg ?></font> <center><img src=?gim=1 width=144><br> <b><?= $title ?></b></center> <hr> <h2>Please upload a new picture and title</h2> <form enctype=multipart/form-data method=post> <input type=hidden name=MAX_FILE_SIZE value=1500000> <input type=hidden name=completed value=1> Please choose an image to upload: <input type=file name=imagefile><br> Please enter the title of that picture: <input name=whatsit><br> then: <input type=submit></form> </body> </head> </html> Well i would like to make it so it can view 10 at 1 time but this piece of code means nothing to me.. I have been programming for 2 months and i dont get this piece.. So maybe if you could explain more how everything works with a few comments and maybe help me add 10 more images to display. Thanks (edited to remove username/password) Quote Link to comment https://forums.phpfreaks.com/topic/98923-help-explain/ Share on other sites More sharing options...
whiteboikyle Posted April 1, 2008 Author Share Posted April 1, 2008 Bump please help? Or at least post something if you cant.. Just would like to know Quote Link to comment https://forums.phpfreaks.com/topic/98923-help-explain/#findComment-506717 Share on other sites More sharing options...
wildteen88 Posted April 1, 2008 Share Posted April 1, 2008 That code allows users to upload an image and the script will store the image in the database. Are you wanting to allow users to upload 10 images at once? Or just display 10 images from the database? Quote Link to comment https://forums.phpfreaks.com/topic/98923-help-explain/#findComment-506774 Share on other sites More sharing options...
whiteboikyle Posted April 2, 2008 Author Share Posted April 2, 2008 Display But can you also help me understand this? Kinda confusing Quote Link to comment https://forums.phpfreaks.com/topic/98923-help-explain/#findComment-507116 Share on other sites More sharing options...
whiteboikyle Posted April 4, 2008 Author Share Posted April 4, 2008 Bump Quote Link to comment https://forums.phpfreaks.com/topic/98923-help-explain/#findComment-509620 Share on other sites More sharing options...
whiteboikyle Posted April 17, 2008 Author Share Posted April 17, 2008 bump Quote Link to comment https://forums.phpfreaks.com/topic/98923-help-explain/#findComment-519093 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.