The Code-Bin
Links
Home
Add your code!
All Listings
About
Latest Entry
Featured Scripts
Author's Website
Latest Entries
FFMPEG Thumbnail Scr...
PHP, 0.8KB
Jul. 29, 10:24pm
John
Z80 Assembler, 190 bytes
Feb. 17, 3:36am
John
Z80 Assembler, 176 bytes
Sep. 13, 2:19am
John
Z80 Assembler, 77 bytes
Sep. 13, 2:18am
John
Z80 Assembler, 209 bytes
Sep. 13, 2:17am
image upload
Posted by: Steve-O | January 23, 2008 @ 1:22pm
Revision 1 - Original post on January 23, 2008 @ 1:21pm
PHP Code
[
Download
]
<?php header("Content-type:$type"); //all the database connection details ?> //Actual html page begins //Image Uploader <form action="<?php echo $_SERVER['php_SELF'];?>" method="post" enctype="multipart/form-data"> <table class="main" cellpadding="0" cellspacing="0" border="0"> <tr> <td><font color="#002157"><b>Upload Image:</b></font>  </td> <td><input type="file" size="40" name="file"></td> </tr> <tr> <td align="right"><font color="#002157"><b>Image URL:</b></font>  </td> <td><input type="text" size="40" name="URL"></td> </tr> <tr> <td> </td> <td><br><input type="submit" name="submit" value="Upload"></td> </tr> </table> </form> //PHP Error Check <?php list($width, $height) = getimagesize($_FILES['file']['tmp_name']); $allowed = array("image/gif", "image/jpeg", "image/pjpeg", "image/png", "image/x-png"); $URL = $_POST["URL"]; $filesize = $_FILES["file"]["size"]/1024; $filetmpName = $_FILES['file']['tmp_name']; $filename = $_FILES["file"]["name"]; $filetype = $_FILES["file"]["type"]; //test viewing an image from the database $query = "SELECT Image, Type FROM $Images WHERE ImageId='11'"; $result= MYSQL_QUERY($query); $data = @ mysql_fetch_array($result); echo $data["Image"]; if($_FILES["file"]["name"]!=""){ if (!in_array($_FILES["file"]["type"], $allowed)){ echo "Invalid file type.<br>"; } elseif ($_FILES["file"]["error"] > 0){ echo "Error: " . $_FILES["file"]["error"] . "<br>"; } elseif($width!=300 || $height!=200){ echo "Bad dimensions.<br>"; } elseif($_FILES["file"]["size"] > 100000){ echo "File is over the 100KB limit.<br>"; } elseif(in_array($_FILES["file"]["type"], $allowed) && $width=300 && $height=200 && $_FILES["file"]["size"] < 100000){ $content =addslashes (file_get_contents($_FILES['file']['tmp_name'])); $query = ("INSERT INTO $Images (Image_Name, Size, Image, Username, Type, URL) VALUES ('$filename', '$filesize', '$content', '$_SESSION[username]', '$filetype', '$URL')"); $result= MYSQL_QUERY($query); echo $query; echo "<br>Upload: " . $_FILES["file"]["name"] . "<br>"; echo "Type: " . $_FILES["file"]["type"] . "<br>"; echo "Size: " . ($_FILES["file"]["size"]/1024) . "KB<br>"; } } else{ echo ""; } ?> <img src="http://www.******.com/imageupload.php?file=11">
Syntax Highlighting
[
Open in new window
]
Author Comments
the image comes up as funny looking symbols. still trying to get the actual image to display
Rating
4.36 / 8
157 Votes