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
<?php
///*
//Server-side PHP file upload code for HTML5 File Drag & Drop demonstration
//Featured on SitePoint.com
//Developed by Craig Buckler (@craigbuckler) of OptimalWorks.net
//*/
$fn = (isset($_SERVER['HTTP_X_FILENAME']) ? $_SERVER['HTTP_X_FILENAME'] : false);
if ($fn) {
// AJAX call
file_put_contents(
'uploads/' . $fn,
file_get_contents('php://input')
);
echo "$fn uploaded";
exit();
}
else {
// form submit
$files = $_FILES['myfile'];
$fn = $files['name'];
move_uploaded_file(
$files['tmp_name'],
'uploads/' . $fn
);
echo "<p>File $fn uploaded.</p>";
}
//
//$xhr = $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest';
//if (!$xhr)
// echo '<textarea>';
//?>
<!---->
<!--// main content of response here-->
<!---->
<?php
//if (!$xhr)
// echo '</textarea>';
//?>