File: test_upload.php

package info (click to toggle)
opendb 0.62p9-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,544 kB
  • ctags: 3,560
  • sloc: php: 26,575; sql: 1,982; sh: 250; makefile: 54
file content (82 lines) | stat: -rw-r--r-- 2,407 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
/* 	OpenDb - Open Lending Database Project
	Copyright (C) 2001,2002 by Jason Pell

	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

// get the specific set of variables depending op php version!
if(is_array($_GET) && count($_GET)>0)
{
	$HTTP_VARS = $_GET;
}
else if(is_array($_POST) && count($_POST)>0)
{
	$HTTP_VARS = $_POST;
}
else if(is_array($HTTP_GET_VARS) && count($HTTP_GET_VARS)>0)
{
	$HTTP_VARS = $HTTP_GET_VARS;
}
else if(is_array($HTTP_POST_VARS) && count($HTTP_POST_VARS)>0)
{
	$HTTP_VARS = $HTTP_POST_VARS;
}

// Get the FILES reference correct.
if(!is_array($HTTP_POST_FILES))
{
	$HTTP_POST_FILES = $_FILES;
}

if($HTTP_VARS['op'] == "upload")
{
	echo "<h1>File uploaded</h1>";

	if(strlen($HTTP_POST_FILES['uploadfile']['name'])>0)
	{
		echo "<p>Upload file name is '".$HTTP_POST_FILES['uploadfile']['name']."'.";

		if(is_uploaded_file($HTTP_POST_FILES['uploadfile']['tmp_name']))
		{
			echo "<p>Temporary upload file is '".$HTTP_POST_FILES['uploadfile']['tmp_name']."'.";

			$tempname = tempnam(NULL, "csvfile");
			if(move_uploaded_file($HTTP_POST_FILES['uploadfile']['tmp_name'], $tempname))
			{
				echo "<p>Upload file moved to $tempname</p>";
				
				// Now get rid of it, as we are finished our test.
				unlink($tempname);
			}
			else
				echo "<p>Upload file NOT moved to $tempname</p>";
		}
		else
			echo "<p>No temporary upload file found!";
	}
	else
		echo "<p>No upload file name found!";
}
else
{
	echo("\n<h1>Upload</h1>");
	echo("\n<form name=\"main\" action=\"$PHP_SELF\" method=\"post\" enctype=\"multipart/form-data\">");
	echo("\n<input type=\"hidden\" name=\"op\" value=\"upload\">");
	echo("<input type=file size=25 name=\"uploadfile\">");
	echo("\n<input type=submit value=\"Upload\">");
	echo("\n</form>");
}
?>