Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <script type='text/javascript' src='jquery-1.9.1.js'></script>
- <!--<script src="ajax.js" type="text/javascript" language="javascript"></script>-->
- <script type='text/javascript'>
- jQuery.noConflict();
- (function($) {
- $(window).load(function(){
- function readURL(input) {
- if (input.files && input.files[0]) {
- var reader = new FileReader();
- reader.onload = function (e) {
- $('#blah').attr('src', e.target.result);
- }
- reader.readAsDataURL(input.files[0]);
- }
- }
- $(".imgInp").change(function(){
- readURL(this);
- });
- });
- })(jQuery);
- </script>
- <script src="mootools-1.2.6-core-nc.js" type="text/javascript" language="javascript"></script>
- <script type='text/javascript'>
- function ajaxrequest(id){
- var req = new Request.HTML({
- method: 'get',
- url: 'display.php?id='+id,
- update: $('imageframe')
- }).send();
- }
- </script>
- <style>
- body { background-color:#eeeeee; font-family:Arial,Helvetica,sans-serif; }
- fieldset { width:350px; }
- fieldset,table,td { font-size:12px; }
- input { border:1px solid #999; }
- .error { color:red; font-size:13px; padding:0 2px; background-color:#FFFFCC; }
- .label { font-weight:bold; }
- .tablecss { background-color:#CCC; }
- .whiterow { background-color:#FFF; }
- #imageframe { padding:2px; overflow:hidden; width:auto; height:auto; margin-top:5px; }
- </style>
- </head>
- <body>
- <fieldset>
- <legend>Form Upload</legend>
- <form enctype='multipart/form-data' name='frmupload' action='' method='POST'>
- <input type="hidden" name="MAX_FILE_SIZE" value="524288" />
- <input name='filename' type='file' class="imgInp">
- <img id="blah" src="#" alt="" style="max-width: 160px; max-height: 120px; border: none;"/>
- <input type='submit' value='Submit' name='submit'>
- </form>
- </fieldset>
- <?php
- include("dbconnect.php");
- if(isset($_POST['submit'])){
- if(is_uploaded_file($_FILES['filename']['tmp_name'])){
- $maxsize=$_POST['MAX_FILE_SIZE'];
- $size=$_FILES['filename']['size'];
- // getting the image info..
- $imgdetails = getimagesize($_FILES['filename']['tmp_name']);
- $mime_type = $imgdetails['mime'];
- //print_r($imgdetails);
- // checking for valid image type
- //if(($mime_type=='image/jpeg')||($mime_type=='image/gif')){
- if($mime_type=='image/jpeg'){
- // checking for size yet again
- if($size<$maxsize){
- $filename=$_FILES['filename']['name'];
- $imgData =addslashes (file_get_contents($_FILES['filename']['tmp_name']));
- $sql="INSERT into image(name,image,type,size) values ('$filename','$imgData','".$mime_type."','".addslashes($imgdetails[3])."')";
- mysql_query($sql,$link) or die(mysql_error());
- }else{
- echo "<font class='error'>Image to be uploaded is too large..Error uploading the image!!</font>";
- }
- }else{
- echo "<font class='error'>Filetype Tidak Di izinkan Selain Format JPG</font>";
- }
- }else{
- switch($_FILES['filename']['error']){
- case 0: //no error; possible file attack!
- echo "<font class='error'>There was a problem with your upload.</font>";
- break;
- case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
- echo "<font class='error'>The file you are trying to upload is too big.</font>";
- break;
- case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
- echo "<font class='error'>The file you are trying to upload is too big.</font>";
- break;
- case 3: //uploaded file was only partially uploaded
- echo "<font class='error'>The file you are trying upload was only partially uploaded.</font>";
- break;
- case 4: //no file was uploaded
- echo "<font class='error'>You must select an image for upload.</font>";
- break;
- default: //a default error, just in case!
- echo "<font class='error'>There was a problem with your upload.</font>";
- break;
- }
- }
- }
- $sql='SELECT * from image';
- $query=mysql_query($sql) or die(mysql_error);
- $listimage = "<fieldset>
- <legend>List Images</legend>
- ";
- $listimage.= "
- <table cellpadding='1' cellspacing='1' width='300' class='tablecss'>
- <tr class='tablecss'>
- <td nowrap class='label'>Image Name</td>
- <td class='label'>Type</td>
- <td class='label'>Size</td>
- </tr>";
- $imageexist=false;
- while($result=mysql_fetch_array($query)){
- $imageexist=true;
- $listimage.= "
- <tr class='whiterow'>
- <td><a href='javascript:void(0)' onclick='ajaxrequest(\"".$result['id']."\")'>".$result['name']."</a></td>
- <td>".str_replace('image/','',$result['type'])."</td>
- <td nowrap>".$result['size']."</td>
- </tr>";
- }
- $listimage.= "
- </table>
- </fieldset>";
- if($imageexist){
- echo $listimage;
- }
- echo "<div id='imageframe' style='border:1px solid red;'></div>";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement