-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfwrite.php
69 lines (58 loc) · 2.02 KB
/
fwrite.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
$state='init';
if (isset($_GET['f_id'])&&(isset($_GET['f_name']))) {
$state='start';
$f_id=$_GET['f_id'];
$f_name=$_GET['f_name'];
define("USERNAME", "[email protected]");
define("PASSWORD", "poqw09123");
define("SECURITY_TOKEN", "vYwfdDbmbtdJI7gRnlJZLwIe");
define("PATH_TOOLKIT","Force.com-Toolkit-for-PHP/");
define("PATH_UNZIP","output_html/html_zip/");
require_once (PATH_TOOLKIT.'soapclient/SforcePartnerClient.php');
echo "<br> login init... ";
$mySforceConnection = new SforcePartnerClient();
echo "<br> login init... new";
$mySforceConnection->createConnection(PATH_TOOLKIT."partner.wsdl.xml");
echo "<br> login init... connect";
$mySforceConnection->login(USERNAME, PASSWORD.SECURITY_TOKEN);
echo "<br> login done ";
//$f_id='00PG0000008Cz7j';
$query = "SELECT Body FROM Attachment WHERE Id='$f_id'";
echo "<br> takeFile q=$query";
$response = $mySforceConnection->query($query);
$data = base64_decode(strip_tags($response->records[0]->any));
$state='data-sf-done;';
echo "<br> data=$data";
//sleep(2);
//---take name---
//$query = "SELECT Name FROM Attachment WHERE Id='$f_id'";
//$response = $this->mySforceConnection->query($query);
//$f_name = $response->records[0]->any;
//echo "<br> f_name=$f_name";
//-----------------------------
$f_full_name=getcwd()."\\upload\\$f_name";
$handle = fopen($f_full_name, 'w');
$res=fwrite($handle, $data);
fclose($handle);
$state.='data-file-write;';
//----unzip----------------
if (strpos($f_name,'.zip')!=false) {
$dir_file_unzip=PATH_UNZIP."/$f_id/";
if (!mkdir($dir_file_unzip)) {
$state.="error-dir;";
} else {
$zip = new ZipArchive;
$res = $zip->open($f_full_name);
if ($res === TRUE) {
$zip->extractTo($dir_file_unzip);
$zip->close();
$state.='data-unzip-done;';
} else {
$state.="error-unzip-dir;"; ;
}
}
}
}
echo "{'state':'$state'}";
?>