PHP Image upload Code _php tutorial

Source: Internet
Author: User
Tags mysql tutorial
PHP Image Upload Code */* This foreign PHP image upload code is a good file and image upload code, and also support the file online management Oh, is a good image management system OH.

PHP Tutorial Image upload Code
/*
This foreign php image upload code is a good file and image upload code, and also support the file online management Oh, is a good image management system OH.
*/

Define (' Max ', 2);

MySQL tutorial _connect (' localhost ', ' your MySQL username ', ' your MySQL password ');
mysql_select_db (' Your MySQL database ');

Switch ($_post[' action ']) {
Case ' upload ':

$file = $_files[' file ' [' Tmp_name '];
$filename = $_files[' file ' [' Name '];

if ($file) {

$max = max * 1024 * 1024;
$q = mysql_query ("select * from ' uploads ' order by ' batch ' desc limit 1");
$r = Mysql_fetch_assoc ($q);
$batch = $r [' Batch '];

if ($filename = = ' Upload.zip ') {

$zip = Zip_open ($file);

if ($zip) {

while ($zip _entry = Zip_read ($zip)) {

$size = zip_entry_filesize ($zip _entry);

$name = Zip_entry_name ($zip _entry);

$type = substr (STRRCHR ($name, '. '), 1);

if (Zip_entry_open ($zip, $zip _entry, "R")) {

$content = Zip_entry_read ($zip _entry, zip_entry_filesize ($zip _entry));
Zip_entry_close ($zip _entry);

}

if ($size > $max) {

Header (' Location:./?error=4 ');
Exit

}

$error = true;

if ($type = = ' gif ' && $error) {

$error = false;

}

if ($type = = ' png ' && $error) {

$error = false;

}

if ($type = = ' jpg ' && $error) {

$error = false;

}

if ($type = = ' jpeg ' && $error) {

$error = false;

}

if ($error) {

Header (' Location:./?error=2 ');

} else {

$id = 1;
$batch 2 = $batch + 1;

while (File_exists ("uploads/$id/$name")) {

$id + +;

}
@mkdir ("uploads/$id");

$fp = @fopen ("uploads/$id/$name", "w");

if (@fwrite ($FP, $content)) {

$q = mysql_query ("INSERT INTO ' uploads ' (' file ', ' batch ') VALUES (' uploads/$id/$name ', ' $batch 2 ')");
$id = mysql_insert_id ();

} else {

Header (' Location:./?error=3 ');

}

Fclose ($FP);

}

}

Header (' Location:./?batch= '. $batch 2);

Zip_close ($zip);

}

} else {

if (filesize ($file) > $max) {

Header (' Location:./?error=4 ');
Exit

}

$error = true;

if (@imagecreatefromjpeg ($file) && $error) {

$error = false;

}

if (@imagecreatefromgif ($file) && $error) {

$error = false;
}

if (@imagecreatefrompng ($file) && $error) {

$error = false;

}

if ($error) {

Header (' Location:./?error=2 ');

} else {

$id = 1;
$batch = $batch + 1;

while (File_exists ("uploads/$id/$filename")) {

$id + +;

}
@mkdir ("uploads/$id");

if (@move_uploaded_file ($file, "uploads/$id/$filename")) {

$q = mysql_query ("INSERT INTO ' uploads ' (' file ', ' batch ') VALUES (' uploads/$id/$filename ', ' $batch ')");
$id = mysql_insert_id ();
Header (' Location:./?image= '. $id);

} else {

Header (' Location:./?error=3 ');

}

}

}

} else {

Header (' Location:./?error=1 ');

}

Exit

Break
}

Header (' content-type:text/html; charset=iso-8859-1 ');
Ob_start (' rewrite ');
function Rewrite ($buffer) {
$host = $_server[' http_host ');
$path = dirname ($_server[' php_self ');
$absolute = "http://$host $path/";
return Preg_replace (' # (href|src|action) = "/#", "1=" $absolute ", $buffer);
}

?>



<title>Jpegr-share photos Instantly</title>










Upload
Help
Terms of Service


Recently uploaded query
$q = mysql_query (' select * from ' uploads ' ORDER by ' ID ' desc limit 15 ');

$q = mysql_query (' Select count (' ID ') as ' count ' from ' uploads ');
$r = Mysql_fetch_assoc ($q);

?>

Images hosted



if ($_get[' p '] = = ' help ') {

?>

Help





  • How does I upload an image?

    Just use the Quick Upload form on the top, or goto the home page to upload an image.


  • What does "must select a file to upload!" mean?

    This means, clicked upload without selecting an image file.


  • What's does "that's a not a valid JPEG, GIF, or PNG image." Mean?

    This means. uploaded a file, but it is not a JPEG, GIF, or PNG image.


  • What does "there is a problem with the server, and we were unable to upload your image." Mean?

    This means your file is accepted, but it does not get saved, you'll need to try again, or upload another image.


  • What does "The file selected were too big, MB is the maximum." Mean?

    This means, tried to upload a file, is too big.



} elseif ($_get[' p '] = = ' Terms-of-service ') {

?>

Terms of Service



When you upload to Jpegr you agree to the following;

    • You won't use the Jpegr to upload pornographic content, any violation of this agreement could result in ban, and immediate re Moval of content.

    • You'll not abuse Jpegr ' s upload form.

    • Any violation could result in permanent ban.



} else {

if (Is_numeric ($_get[' image ')) {

$q = mysql_query ("select * from ' uploads ' where ' id ' = ' $_get[image] ');
$r = Mysql_fetch_assoc ($q);
$root _ = ' http://'. $_server[' Http_host '. DirName ($_server[' php_self '). '/';

?>

Here is your image



">click here to view your image


Direct link to your image



share with your friends

"Onfocus=" This.select (); "/>

Post link to MySpace or website

"Onfocus=" This.select (); "/>

Post to a forum

"Onfocus=" This.select (); "/>

If you want to upload another image, you can go back or use the form below!



}

if (Is_numeric ($_get[' batch ')) {

$q = mysql_query ("select * from ' uploads ' where ' batch ' = ' $_get[batch] ');

?>

viewing Batch #



To view a image in full size, just click it.



while ($r = Mysql_fetch_assoc ($q)) {

?>
">" alt= "Image # " border= "0" style= "max-width:75px;"/>

}

?>





Beta Image Slideshow


turn on JavaScript to view our slideshows.







Share this batch with your friends




Batch Viewer



If you want to upload another batch, you can go back or use the form below!



}

?>

Upload an image or photo



}

?>




??????
mysql_connect (' localhost ', ' your MySQL username ', ' your MySQL password ');
mysql_select_db (' Your MySQL database ');
if ($_get[' delete ']) {
$sql = "Select * from ' uploads ' where ' id ' = ' $_get[delete] '";
$q = mysql_query ($sql);
$r = Mysql_fetch_assoc ($q);
Unlink ($_server[' document_root '). '/' . $r [' file '];
$sql = "Delete from ' uploads ' where ' id ' = ' $_get[delete] '";
$q = mysql_query ($sql);
Header (' Location: '. $_server[' Http_referer ');
Exit
}
?>




<title>Jpegr Administration</title>



$sql = ' Select Ceil (count (' id ')/+) as ' count ' from ' uploads ';
$q = mysql_query ($sql);
$r = Mysql_fetch_assoc ($q);
$pages = $r [' count '];
$offset = ($_get[' page '] > 0 && $_get[' page '] <= $pages)? ($_get[' page ')-1) * 20:0;
for ($i = 1; $i <= $pages; $i + +) {
$class = ($_get[' page ') = = $i | | $i = = = 1 &&!$_get[' page '])? ' class= ' current ': ' class= ' page ';
?>
" >
}
?>



















$sql = "Select * from ' uploads ' ORDER by ' ID ' desc limit $offset, 20"; $q = mysql_query ($sql); while ($r = Mysql_fetch_assoc ($q)) {?> }?>
Id FileName Action
"target=" _blank ">view," onclick= "return confirm (' is you sure do want to delete" "? ');" >delete


Css??
HTML, Body {
Font-family:sans-serif;
font-size:12px;
width:800px;
margin:40px Auto;
}
A
Color: #105cb6;
Text-decoration:none;
}
H1 {
margin:0px 0px 10px 0px;
}
H1 a {
-moz-outline-width:0px;
}
H1 a img {
border:0px;
}
h3 {
margin:4px;
}
a:hover {
Text-decoration:underline;
}
#menu {
Background-color: #e5f5ff;
padding:8px;
border:1px solid #0099ff;
position:relative;
}
#menu a {
Font-weight:bold;
margin:0px 8px 0px 0px;
}
#menu A:hover {
Text-decoration:underline;
}
#menu. Right {
margin:0px;
padding:0px;
Position:absolute;
top:4px;
right:4px;
}
#menu. Input {
Background-color: #ffffff;
padding:2px;
border:1px solid #0066ff;
}
#menu. button {
Font-family:sans-serif;
padding:2px;
Cursor:pointer;
}
#menu Label {
Cursor:pointer;
}
#ads {
Background-color: #fde5f3;
MARGIN:8PX 0px;
border:1px solid #ec008c;
}
#recent {
Background-color: #e6fec9;
MARGIN:8PX 0px;
padding:2px;
border:1px solid #9dca68;
}
#main {
Background-color: #fffee5;
padding:8px;
border:1px solid #fff200;
}
#main H2 {
font-size:16px;
Color: #222222;
margin:0px;
}
#main Form {
MARGIN:4PX 8px;
}
#main Label {
Cursor:pointer;
}
#main. button {
Font-family:sans-serif;
margin:2px 0px 0px 0px;
padding:2px;
Cursor:pointer;
}
#main. Right {
font-size:14px;
Float:right;
padding:0px 0px 2px 0px;
border-bottom:1px solid #444444;
}
#main Div {
MARGIN:4PX 8px;
}
#main Div Label {
Font-weight:bold;
}
#main Div Input {
Font-family:sans-serif;
font-size:12px;
width:680px;
padding:2px;
margin:2px 0px 4px 4px;
}
#main Div Li {
margin-bottom:8px;
}
#links {
Background-color: #e9e8e8;
margin:8px 0px 0px 0px;
PADDING:4PX 0px;
border:1px solid #231f20;
}
. spacer {
height:4px;
Overflow:hidden;
}

#slider {
Color: #ffffff;
Background-color: #232323;
height:400px;
margin:10px;
padding:5px;
border:1px solid #121212;
}

#slider H3 {
Color: #ffffff;
font-size:14px;
line-height:20px;
Background-color: #343434;
height:20px;
margin: -5px-5px 15px-5px;
padding:5px;
}

#slider #slide #image {
max-height:350px;
}

SOURCE Download Address

Http://down.php100.com/php/2010/0927/20956.html


http://www.bkjia.com/PHPjc/444844.html www.bkjia.com true http://www.bkjia.com/PHPjc/444844.html techarticle PHP Image Upload Code */* This foreign PHP image upload code is a good file and image upload code, and also support the file online management Oh, is a good picture management system Oh ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.