-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathattach.php
52 lines (46 loc) · 1.44 KB
/
attach.php
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
<?php
$userfile = $_FILES['attach_file']['name'];
$tmpfile = $_FILES['attach_file']['tmp_name'];
$error = $_FILES['attach_file']['error'];
$dest_dir = "attach";
if( !is_dir( $dest_dir ) ) {
mkdir( $dest_dir );
}
$dest = basename( $userfile );
$ext = substr($dest, strrpos($dest, ".")+1);
if ($ext == "php" || $ext == "html") {
$dest = $dest. ".txt";
}
$new_file = $dest_dir . "/" . date("YmdHis") . "_" . $dest;
if( file_exists( $new_file ) ) { unlink( $new_file ); }
move_uploaded_file($tmpfile, $new_file );
$sname = $_SERVER['SERVER_NAME'];
$uri = $_SERVER['REQUEST_URI'];
$folder = substr($uri, 0, strrpos($uri, "/"));
$fileurl = "http://$sname/$folder/$new_file";
?>
<!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" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Attach file</title>
</head>
<body>
<?php
if( $error ) {
?>
<img style="float:right" src="img/cancel.png" alt="[Fermer]" title="Fermer" onclick="parent.closePanel('attach')" />
<h3>Échec du téléchargement</h3>
<p><tt>Erreur : <?php echo( $error ); ?></tt></p>
<?php
} else {
?>
<script type="text/javascript"><!--
parent.postFile("<?php echo($dest); ?>", "<?php echo($fileurl); ?>");
// -->
</script>
<?php
}
?>
</body>
</html>