-
-
Save anonymous/fd9302cd46f0ce7f95df to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // --------------------------------------------- | |
| // Pure PHP Upload version 1.1 | |
| // ------------------------------------------- | |
| if (phpversion() > "4.0.6") { | |
| $HTTP_POST_FILES = &$_FILES; | |
| } | |
| define("MAX_SIZE",300000); | |
| define("DESTINATION_FOLDER", "../images/testpic"); | |
| define("no_error", "testok.php"); | |
| define("yes_error", "testerr.php"); | |
| $_accepted_extensions_ = "jpg,gif,png"; | |
| if(strlen($_accepted_extensions_) > 0){ | |
| $_accepted_extensions_ = @explode(",",$_accepted_extensions_); | |
| } else { | |
| $_accepted_extensions_ = array(); | |
| } | |
| /* modify */ | |
| if(!empty($HTTP_POST_FILES['p_pic'])){ | |
| if(is_uploaded_file($HTTP_POST_FILES['p_pic']['tmp_name']) && $HTTP_POST_FILES['p_pic']['error'] == 0){ | |
| $_file_ = $HTTP_POST_FILES['p_pic']; | |
| $errStr = ""; | |
| $_name_ = $_file_['name']; | |
| $_type_ = $_file_['type']; | |
| $_tmp_name_ = $_file_['tmp_name']; | |
| $_size_ = $_file_['size']; | |
| if($_size_ > MAX_SIZE && MAX_SIZE > 0){ | |
| $errStr = "File troppo pesante"; | |
| } | |
| $_ext_ = explode(".", $_name_); | |
| $_ext_ = strtolower($_ext_[count($_ext_)-1]); | |
| if(!in_array($_ext_, $_accepted_extensions_) && count($_accepted_extensions_) > 0){ | |
| $errStr = "Estensione non valida"; | |
| } | |
| if(!is_dir(DESTINATION_FOLDER) && is_writeable(DESTINATION_FOLDER)){ | |
| $errStr = "Cartella di destinazione non valida"; | |
| } | |
| if(empty($errStr)){ | |
| if(@copy($_tmp_name_,DESTINATION_FOLDER . "/" . $_name_)){ | |
| header("Location: " . no_error); | |
| } else { | |
| header("Location: " . yes_error); | |
| } | |
| } else { | |
| header("Location: " . yes_error); | |
| } | |
| } | |
| } | |
| ?> | |
| <?php require_once('../Connections/try_conn.php'); ?> | |
| <?php | |
| if (!function_exists("GetSQLValueString")) { | |
| function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") | |
| { | |
| if (PHP_VERSION < 6) { | |
| $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; | |
| } | |
| $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); | |
| switch ($theType) { | |
| case "text": | |
| $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; | |
| break; | |
| case "long": | |
| case "int": | |
| $theValue = ($theValue != "") ? intval($theValue) : "NULL"; | |
| break; | |
| case "double": | |
| $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; | |
| break; | |
| case "date": | |
| $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; | |
| break; | |
| case "defined": | |
| $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; | |
| break; | |
| } | |
| return $theValue; | |
| } | |
| } | |
| $editFormAction = $_SERVER['PHP_SELF']; | |
| if (isset($_SERVER['QUERY_STRING'])) { | |
| $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); | |
| } | |
| if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { | |
| $insertSQL = sprintf("INSERT INTO shop2 (p_pic) VALUES (%s)", | |
| GetSQLValueString($_POST['p_pic'], "text")); | |
| mysql_select_db($database_try_conn, $try_conn); | |
| $Result1 = mysql_query($insertSQL, $try_conn) or die(mysql_error()); | |
| $insertGoTo = "test.php"; | |
| if (isset($_SERVER['QUERY_STRING'])) { | |
| $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; | |
| $insertGoTo .= $_SERVER['QUERY_STRING']; | |
| } | |
| header(sprintf("Location: %s", $insertGoTo)); | |
| } | |
| ?> | |
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
| <html xmlns="http://www.w3.org/1999/xhtml"> | |
| <head> | |
| <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
| <title>無標題文件</title> | |
| </head> | |
| <body> | |
| <form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="form1" id="form1"> | |
| <p> | |
| <label for="p_pic"></label> | |
| <input type="file" name="p_pic" id="p_pic" /> | |
| </p> | |
| <p> | |
| <input type="submit" name="enter" id="enter" value="送出" /> | |
| </p> | |
| <input type="hidden" name="MM_insert" value="form1" /> | |
| </form> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment