Skip to content

Instantly share code, notes, and snippets.

Created December 26, 2013 08:48
Show Gist options
  • Select an option

  • Save anonymous/57acd7af18a01aabf1bf to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/57acd7af18a01aabf1bf to your computer and use it in GitHub Desktop.
<?php
// ---------------------------------------------
// Pure PHP Upload version 1.1
// -------------------------------------------
if (phpversion() > "4.0.6") {
$HTTP_POST_FILES = &$_FILES;
}
define("MAX_SIZE",300000);
define("DESTINATION_FOLDER", "../images/test");
define("no_error", "testok.php");
define("yes_error", "testerr.php");
$_accepted_extensions_ = "jpg,png,gif";
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);
}
}
}
?>
<!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 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>
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment