xcoderx Posted August 14, 2009 Share Posted August 14, 2009 friends anyone got code to show only images from a dir with a limit of 10 images perpage? Thanx Link to comment https://forums.phpfreaks.com/topic/170318-listing-only-images-from-a-dir-escaping-other-files/ Share on other sites More sharing options...
trq Posted August 14, 2009 Share Posted August 14, 2009 Take a look at glob. Link to comment https://forums.phpfreaks.com/topic/170318-listing-only-images-from-a-dir-escaping-other-files/#findComment-898449 Share on other sites More sharing options...
xcoderx Posted August 14, 2009 Author Share Posted August 14, 2009 ok i got how to list but the pagination of 10 images a page, am not good at it, could u help thrope? Here the code <?php //define a maxim size for the uploaded images in Kb define ("MAX§SIZE","100"); //This function reads the extension of the file. It is used to determine if the file is an image by checking the extension. function getExtension(¤str) ä ¤i = strrpos(¤str,"."); if (!¤i) ä return ""; ñ ¤l = strlen(¤str) - ¤i; ¤ext = substr(¤str,¤i+1,¤l); return ¤ext; ñ //This variable is used as a flag. The value is initialized with 0 (meaning no error found) //and it will be changed to 1 if an errro occures. //If the error occures the file will not be uploaded. ¤errors=0; //checks if the form has been submitted if(isset(¤§POSTÄ'Submit'Ñ)) ä ç//reads the name of the file the user submitted for uploading ç¤image=¤§FILESÄ'image'ÑÄ'name'Ñ; ç//if it is not empty çif (¤image) çä ç//get the original name of the file from the clients machine çç¤filename = stripslashes(¤§FILESÄ'image'ÑÄ'name'Ñ); ç//get the extension of the file in a lower case format çç¤extension = getExtension(¤filename); çç¤extension = strtolower(¤extension); ç//if it is not a known extension, we will suppose it is an error and will not upload the file, ç//otherwise we will do more tests if ((¤extension != "jpg") && (¤extension != "jpeg") && (¤extension != "png") && (¤extension != "gif")) ççä çç//print error message çççecho '<h1>Unknown extension!</h1>'; ççç¤errors=1; ççñ ççelse ççä //get the size of the image in bytes //¤§FILESÄ'image'ÑÄ'tmp§name'Ñ is the temporary filename of the file //in which the uploaded file was stored on the server ¤size=filesize(¤§FILESÄ'image'ÑÄ'tmp§name'Ñ); //compare the size with the maxim size we defined and print error if bigger if (¤size > MAX§SIZE*1024) ä çecho '<h1>You have exceeded the size limit!</h1>'; ç¤errors=1; ñ //we will give an unique name, for example the time in unix time format ¤image§name=time().'.'.¤extension; //the new name will be containing the full path where will be stored (images folder) ¤newname="upload/".¤image§name; //we verify if the image has been uploaded, and print error instead ¤copied = copy(¤§FILESÄ'image'ÑÄ'tmp§name'Ñ, ¤newname); if (!¤copied) ä çecho '<h1>Copy unsuccessfull!</h1>'; ç¤errors=1; ññññ //If no errors registred, print the success message if(isset(¤§POSTÄ'Submit'Ñ) && !¤errors) ä çecho "<h1>File Uploaded Successfully! Try again!</h1>"; ñ ?> <!--next comes the form, you must set the enctype to "multipart/frm-data" and use an input type "file" --> <form name="newad" method="post" enctype="multipart/form-data" action=""> <table> ç<tr><td><input type="file" name="image"></td></tr> ç<tr><td><input name="Submit" type="submit" value="Upload image"></td></tr> </table>ç </form> Link to comment https://forums.phpfreaks.com/topic/170318-listing-only-images-from-a-dir-escaping-other-files/#findComment-898456 Share on other sites More sharing options...
trq Posted August 14, 2009 Share Posted August 14, 2009 Again, take a look at glob. Link to comment https://forums.phpfreaks.com/topic/170318-listing-only-images-from-a-dir-escaping-other-files/#findComment-898469 Share on other sites More sharing options...
xcoderx Posted August 14, 2009 Author Share Posted August 14, 2009 pmpl ok ;-) u pullin my legs hehe Link to comment https://forums.phpfreaks.com/topic/170318-listing-only-images-from-a-dir-escaping-other-files/#findComment-898472 Share on other sites More sharing options...
trq Posted August 15, 2009 Share Posted August 15, 2009 What? Link to comment https://forums.phpfreaks.com/topic/170318-listing-only-images-from-a-dir-escaping-other-files/#findComment-898556 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.