source: code/Website/php-ofc-library/ofc_upload_image.php@ 7855

Last change on this file since 7855 was 7849, checked in by dennisw, 15 years ago
File size: 1.6 KB
Line 
1<?php
2
3//
4// In Open Flash Chart -> save_image debug mode, you
5// will see the 'echo' text in a new window.
6//
7
8/*
9
10print_r( $_GET );
11print_r( $_POST );
12print_r( $_FILES );
13
14print_r( $GLOBALS );
15print_r( $GLOBALS["HTTP_RAW_POST_DATA"] );
16
17*/
18
19
20// default path for the image to be stored //
21$default_path = '../tmp-upload-images/';
22
23if (!file_exists($default_path)) mkdir($default_path, 0777, true);
24
25// full path to the saved image including filename //
26$destination = $default_path . basename( $_GET[ 'name' ] );
27
28echo 'Saving your image to: '. $destination;
29// print_r( $_POST );
30// print_r( $_SERVER );
31// echo $HTTP_RAW_POST_DATA;
32
33//
34// POST data is usually string data, but we are passing a RAW .png
35// so PHP is a bit confused and $_POST is empty. But it has saved
36// the raw bits into $HTTP_RAW_POST_DATA
37//
38
39$jfh = fopen($destination, 'w') or die("can't open file");
40fwrite($jfh, $HTTP_RAW_POST_DATA);
41fclose($jfh);
42
43//
44// LOOK:
45//
46exit();
47
48
49//
50// PHP5:
51//
52
53
54// default path for the image to be stored //
55$default_path = 'tmp-upload-images/';
56
57if (!file_exists($default_path)) mkdir($default_path, 0777, true);
58
59// full path to the saved image including filename //
60$destination = $default_path . basename( $_FILES[ 'Filedata' ][ 'name' ] );
61
62// move the image into the specified directory //
63if (move_uploaded_file($_FILES[ 'Filedata' ][ 'tmp_name' ], $destination)) {
64 echo "The file " . basename( $_FILES[ 'Filedata' ][ 'name' ] ) . " has been uploaded;";
65} else {
66 echo "FILE UPLOAD FAILED";
67}
68
69
70?>
Note: See TracBrowser for help on using the repository browser.