Php image upload code. Php image upload code * this foreign php image upload code is a good file and image upload code and supports online file management, is a good image management system. php image upload code/* This php image upload code abroad is a good file and image upload code, it also supports online file management. it is a good image management system.
Php Tutorial image upload code
/*
This foreign php image upload code is a good file and image upload code, and also supports online file management. it is a good image management system.
*/
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;
$ Batch2 = $ 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', '$ batch2 ')");
$ Id = mysql_insert_id ();
} Else {
Header ('Location :./? Error = 3 ');
}
Fclose ($ fp );
}
}
Header ('Location :./? Batch = '. $ batch2 );
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 );
}
?>
Alibaba R-share photos instantly