Upload using PHP
On Linux servers, you have the option to use PHP, JavaScript to upload files to a server. First, you must prepare the server to receive the data. If you want to save any data on the server, you must have the directory where data will be saved, set the right to registration.
Php upload is how, by using php and the POST method to upload files to the server. Is slow and inefficient, because the file size is limited to 2 MB. It has the ability to take advantage of each customer, if its domain is located on server Linux variant that supports PHP, JavaScript.
Note: the name of the temporary directory is not possible to individually set otherwise.
Examples of use:
1. When safe_mod = onUsing a text editor, create a file named upload. php and write the following code:
<html>
<head>
<title>Prenos souboru pri safe_mod = On</title>
</head>
<body>
<?php
if ($_POST["odeslano"] == true) {
if (!is_file($_FILES['hloupost']['tmp_name'])) die ("Žádný soubor jste neuploadoval");
$conn_id = ftp_connect('moje.ftp.cz');
if (!$login_result = ftp_login($conn_id, 'muj_ftp_login', 'me_ftp_heslo')) {
die('Pripojeni k FTP serveru se nezdarilo');
}
$local_file = $_FILES['hloupost']['tmp_name'];
$remote_file = $_FILES['hloupost']['name'];
if (!ftp_put($conn_id, $remote_file, $local_file, FTP_BINARY)) {
die('Prenos souboru se nezdaril');
} else {
echo "Soubor <strong>".$_FILES['hloupost']['name']."</strong> z Vaseho PC";
echo " typu <strong>".$_FILES['hloupost']['type']."</strong>";
echo " o velikosti <strong>".$_FILES['hloupost']['size']."</strong> bajtu";
echo " byl na serveru ulozen pod docasnym nazevem <strong>".$_FILES['hloupost']['tmp_name']."</strong>";
echo " a nasledne zpracovan.<br /><br />";
}
ftp_close($conn_id);
}
?>
Nahrani souboru na server
<form method="post" enctype="multipart/form-data">
<table border="1" >
<tr>
<td>Soubor: </td>
<td><input type="file" name="hloupost" accpet="text" /></td>
</tr>
<tr>
<td colspan="2">
<input type="hidden" name="odeslano" value="true" />
<p align="center"><input type="submit" value="Odeslat" /></td>
</tr>
</table>
</form>
</body>
</html>
2. When safe_mod = off
Using a text editor, create a file named uploadexec. php and write the following code:
<html>
<head>
<title>Prenos souboru pri safe_mod = On</title>
</head>
<body>
<?php
if ($_POST["odeslano"] == true) {
if (!is_file($_FILES['hloupost']['tmp_name'])) die ("Žádný soubor jste neuploadoval");
$local_file = $_FILES['hloupost']['tmp_name'];
$remote_file = $_FILES['hloupost']['name'];
if (!move_uploaded_file($remote_file, $local_file)) {
die('Prenos souboru se nezdaril');
} else {
echo "Soubor <strong>".$_FILES['hloupost']['name']."</strong> z Vaseho PC";
echo " typu <strong>".$_FILES['hloupost']['type']."</strong>";
echo " o velikosti <strong>".$_FILES['hloupost']['size']."</strong> bajtu";
echo " byl na serveru ulozen pod docasnym nazevem <strong>".$_FILES['hloupost']['tmp_name']."</strong>";
echo " a nasledne zpracovan.<br /><br />";
}
}
?>
Nahrani souboru na server
<form method="post" enctype="multipart/form-data">
<table border="1" >
<tr>
<td>Soubor: </td>
<td><input type="file" name="hloupost" accpet="text" /></td>
</tr>
<tr>
<td colspan="2">
<input type="hidden" name="odeslano" value="true" />
<p align="center"><input type="submit" value="Odeslat" /></td>
</tr>
</table>
</form>
</body>
</html>
Both files then nahrejte to the server in one directory, and now you can test the function by calling the first file upload php in your favorite Internet browser. After selecting the file and clicking on the button "Send File" file will be using the function, defined in the file uploadexec. php, upload to the server to the directory in which are located the control files.