Zip downloaden en uitpakken via php
Ik wil graag een zip file van een andere site afhalen en die vervolgens uitpakken op mijn site en de bestaande files ermee overschrijven.
Hoe kan ik dit doen?
Helaas kan ik geen system(wget..); doen.
Script wat ik tot nu toe heb, maar niet werkt:
Code (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
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
<?php
// Set to the directory to extract archive to
$scheiden = $_SERVER['SCRIPT_FILENAME'];
$var = explode("/", $scheiden);
$extractTo = '/'.$var["1"].'/'.$var["2"].'/'.$var["3"].'/'.$var["4"].'/'.$var["5"].'/';
// Set remote FTP server
$ftp_server = '..';
// FTP login details:
$ftp_user_name = '..';
$ftp_user_pass = '..';
// Name of the zip file
$filename = 'updates.zip';
////////////////////////////////////////////////////////////
// END OF CONFIGURATION
////////////////////////////////////////////////////////////
// Connect to the FTP server
$ftp_id = ftp_connect($ftp_server);
// Login to FTP server
$login_result = ftp_login($ftp_id, $ftp_user_name, $ftp_user_pass);
// Download file from the FTP server
if (ftp_get($ftp_id, $filename, $filename, FTP_BINARY))
{
$zip = new ZipArchive;
// Open the zip file
if ($zip->open($filename))
{
// Extract the zip file
$zip->extractTo($extractTo);
// Close the ZIP file
$zip->close();
echo "Klaar!";
}
else
{
echo "Problemen met het unzippen van $filename. ";
}
}
else
{
echo "Problemen met het downloaden.. $filename \n";
}
// Close the FTP connection
ftp_close($ftp_id);
// Remove the zip file
@unlink($filename);
?>
// Set to the directory to extract archive to
$scheiden = $_SERVER['SCRIPT_FILENAME'];
$var = explode("/", $scheiden);
$extractTo = '/'.$var["1"].'/'.$var["2"].'/'.$var["3"].'/'.$var["4"].'/'.$var["5"].'/';
// Set remote FTP server
$ftp_server = '..';
// FTP login details:
$ftp_user_name = '..';
$ftp_user_pass = '..';
// Name of the zip file
$filename = 'updates.zip';
////////////////////////////////////////////////////////////
// END OF CONFIGURATION
////////////////////////////////////////////////////////////
// Connect to the FTP server
$ftp_id = ftp_connect($ftp_server);
// Login to FTP server
$login_result = ftp_login($ftp_id, $ftp_user_name, $ftp_user_pass);
// Download file from the FTP server
if (ftp_get($ftp_id, $filename, $filename, FTP_BINARY))
{
$zip = new ZipArchive;
// Open the zip file
if ($zip->open($filename))
{
// Extract the zip file
$zip->extractTo($extractTo);
// Close the ZIP file
$zip->close();
echo "Klaar!";
}
else
{
echo "Problemen met het unzippen van $filename. ";
}
}
else
{
echo "Problemen met het downloaden.. $filename \n";
}
// Close the FTP connection
ftp_close($ftp_id);
// Remove the zip file
@unlink($filename);
?>
Hoe kan ik dit het beste doen?
Error is trouwens:
Code (php)
1
2
3
2
3
Warning: ftp_get(updates.zip) [function.ftp-get]: failed to open stream: Permission denied in ....
en
Warning: ftp_get() [function.ftp-get]: Error opening updates.zip
en
Warning: ftp_get() [function.ftp-get]: Error opening updates.zip
Alvast bedankt
1. moet je in het path staan waar de te downloaden files staan
of
2. moet je het volledige path opgeven
Als ik public_html of /public_html doe is er nog steeds geen resultaat helaas.
Helaas nog niet gelukt, iemand een idee?
--> $_SERVER['DOCUMENT_ROOT']
--> http://php.net/manual/en/function.ftp-chdir.php [/] daar/waar/de/op/te/halen/file/staat
De error is Warning: ftp_get(updates.zip) [function.ftp-get]: failed to open stream: Permission denied in ....
Code (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
70
71
72
73
74
75
76
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
<?php
// Set to the directory to extract archive to
//echo $_SERVER['DOCUMENT_ROOT'];
$scheiden = $_SERVER['SCRIPT_FILENAME'];
$var = explode("/", $scheiden);
$extractTo = $_SERVER['DOCUMENT_ROOT'].'/';
// Set remote FTP server
$ftp_server = 'ip';
// FTP login details:
$ftp_user_name = 'user';
$ftp_user_pass = 'pass';
// Name of the zip file
$filename = 'updates.zip';
////////////////////////////////////////////////////////////
// END OF CONFIGURATION
////////////////////////////////////////////////////////////
// Connect to the FTP server
$ftp_id = ftp_connect($ftp_server);
// Login to FTP server
$login_result = ftp_login($ftp_id, $ftp_user_name, $ftp_user_pass);
if ((!$ftp_id) || (!$login_result)) {
die("FTP connection has failed !");
}
ftp_pasv($ftp_id, true);
echo "Current directory: " . ftp_pwd($ftp_id) . "<br />";
if (ftp_chdir($ftp_id, "/domains/domeinnaam.com/public_html/")) {
echo "Current directory is now: " . ftp_pwd($ftp_id) . "<br />";
} else {
echo "Couldn't change directory\n";
}
// Download file from the FTP server
if (ftp_get($ftp_id, $filename, $filename, FTP_BINARY))
{
$zip = new ZipArchive;
// Open the zip file
if ($zip->open($filename))
{
// Extract the zip file
$zip->extractTo($extractTo);
// Close the ZIP file
$zip->close();
echo "De webshop is nu geupdated!";
}
else
{
echo "Problemen met het unzippen van $filename. Neem contact op met de beheerder";
}
}
else
{
echo "Problemen met het downloaden.. $filename \n";
}
// Close the FTP connection
ftp_close($ftp_id);
// Remove the zip file
@unlink($filename);
?>
// Set to the directory to extract archive to
//echo $_SERVER['DOCUMENT_ROOT'];
$scheiden = $_SERVER['SCRIPT_FILENAME'];
$var = explode("/", $scheiden);
$extractTo = $_SERVER['DOCUMENT_ROOT'].'/';
// Set remote FTP server
$ftp_server = 'ip';
// FTP login details:
$ftp_user_name = 'user';
$ftp_user_pass = 'pass';
// Name of the zip file
$filename = 'updates.zip';
////////////////////////////////////////////////////////////
// END OF CONFIGURATION
////////////////////////////////////////////////////////////
// Connect to the FTP server
$ftp_id = ftp_connect($ftp_server);
// Login to FTP server
$login_result = ftp_login($ftp_id, $ftp_user_name, $ftp_user_pass);
if ((!$ftp_id) || (!$login_result)) {
die("FTP connection has failed !");
}
ftp_pasv($ftp_id, true);
echo "Current directory: " . ftp_pwd($ftp_id) . "<br />";
if (ftp_chdir($ftp_id, "/domains/domeinnaam.com/public_html/")) {
echo "Current directory is now: " . ftp_pwd($ftp_id) . "<br />";
} else {
echo "Couldn't change directory\n";
}
// Download file from the FTP server
if (ftp_get($ftp_id, $filename, $filename, FTP_BINARY))
{
$zip = new ZipArchive;
// Open the zip file
if ($zip->open($filename))
{
// Extract the zip file
$zip->extractTo($extractTo);
// Close the ZIP file
$zip->close();
echo "De webshop is nu geupdated!";
}
else
{
echo "Problemen met het unzippen van $filename. Neem contact op met de beheerder";
}
}
else
{
echo "Problemen met het downloaden.. $filename \n";
}
// Close the FTP connection
ftp_close($ftp_id);
// Remove the zip file
@unlink($filename);
?>
Dit is de ouput wat ik krijg:
Code (php)
1
2
3
4
5
6
7
2
3
4
5
6
7
Current directory: /
Current directory is now: /domains/domeinnaam/public_html
Warning: ftp_get(updates.zip) [function.ftp-get]: failed to open stream: Permission denied in /home/user/domains/domeinnaam.com/public_html/webshop/admin/run_updater.php on line 45
Warning: ftp_get() [function.ftp-get]: Error opening updates.zip in /home/user/domains/domeinnaam.com/public_html/webshop/admin/run_updater.php on line 45
Problemen met het downloaden.. updates.zip
Current directory is now: /domains/domeinnaam/public_html
Warning: ftp_get(updates.zip) [function.ftp-get]: failed to open stream: Permission denied in /home/user/domains/domeinnaam.com/public_html/webshop/admin/run_updater.php on line 45
Warning: ftp_get() [function.ftp-get]: Error opening updates.zip in /home/user/domains/domeinnaam.com/public_html/webshop/admin/run_updater.php on line 45
Problemen met het downloaden.. updates.zip
Ik heb echt geen idee wat ik fout doe..
Ik connect trouwens naar de andere site via de directadmin user ervan.