*/
/**
- * Transform a string in a path by seperating each letters by a '/'.
+ * Transform a string in a path by separating each letters by a '/'.
* @return path finishing with a '/'
*/
function s2p($s)
}
}
- /* file informations */
+ /* file information */
$hash = jirafeau_hash_file($file_hash_method, $file['tmp_name']);
$name = str_replace(NL, '', trim($file['name']));
$mime_type = $file['type'];
}
/**
- * Read link informations
- * @return array containing informations.
+ * Read link information
+ * @return array containing information.
*/
function jirafeau_get_link($hash)
{
/* Push new found directory. */
$stack[] = $d . $node . '/';
} elseif (is_file($d . $node)) {
- /* Read link informations. */
+ /* Read link information. */
$l = jirafeau_get_link($node);
if (!count($l)) {
continue;
if (!empty($link_hash) && $link_hash != $node) {
continue;
}
- /* Print link informations. */
+ /* Print link information. */
echo '<tr>';
echo '<td>' .
'<strong><a id="upload_link" href="f.php?h='. jirafeau_escape($node) .'" title="' .
/* Push new found directory. */
$stack[] = $d . $node . '/';
} elseif (is_file($d . $node)) {
- /* Read link informations. */
+ /* Read link information. */
$l = jirafeau_get_link(basename($node));
if (!count($l)) {
continue;
/**
- * Clean old async transferts.
+ * Clean old async transfers.
* @return number of cleaned files.
*/
function jirafeau_admin_clean_async()
/* Push new found directory. */
$stack[] = $d . $node . '/';
} elseif (is_file($d . $node)) {
- /* Read async informations. */
+ /* Read async information. */
$a = jirafeau_get_async_ref(basename($node));
if (!count($a)) {
continue;
}
- /* Delete transferts older than 1 hour. */
+ /* Delete transfers older than 1 hour. */
if (time() - $a['last_edited'] > 3600) {
jirafeau_async_delete(basename($node));
$count++;
}
/**
- * Read async transfert informations
- * @return array containing informations.
+ * Read async transfer information
+ * @return array containing information.
*/
function jirafeau_get_async_ref($ref)
{
}
/**
- * Delete async transfert informations
+ * Delete async transfer information
*/
function jirafeau_async_delete($ref)
{
/**
* Init a new asynchronous upload.
- * @param $finename Name of the file to send
+ * @param $filename Name of the file to send
* @param $one_time One time upload parameter
* @param $key eventual password (or blank)
* @param $time time limit
* @param $ip ip address of the client
- * @return a string containing a temporary reference followed by a code or the string 'Error'
+ * @return a string containing a temporary reference followed by a code or a string starting with 'Error'
*/
function jirafeau_async_init($filename, $type, $one_time, $key, $time, $ip)
{
- $res = 'Error';
-
/* Create temporary folder. */
$ref;
$p;
} while (file_exists($p));
@mkdir($p, 0755, true);
if (!file_exists($p)) {
- echo 'Error';
- return;
+ return 'Error: cannot create async folder.';
}
/* touch empty data file */
$password = md5($key);
}
- /* Store informations. */
+ /* Store information. */
$p .= $ref;
$handle = fopen($p, 'w');
fwrite(
* @param $file piece of data
* @param $code client code for this operation
* @param $max_file_size maximum allowed file size
- * @return a string containing a next code to use or the string "Error"
+ * @return a string containing a next code to use or a string starting with 'Error'
*/
function jirafeau_async_push($ref, $data, $code, $max_file_size)
{
$a = jirafeau_get_async_ref($ref);
/* Check some errors. */
- if (count($a) == 0
- || $a['next_code'] != "$code"
- || empty($data['tmp_name'])
- || !is_uploaded_file($data['tmp_name'])) {
- return 'Error';
+ if (count($a) == 0) {
+ return "Error: cannot find transfer";
+ }
+ if ($a['next_code'] != "$code") {
+ return "Error: bad transfer code";
+ }
+ if ($data['error'] != UPLOAD_ERR_OK) {
+ // Check error code in https://www.php.net/manual/en/features.file-upload.errors.php
+ $data_details = print_r($data, true);
+ return "Error: upload error: {$data_details}";
+ }
+ if (empty($data['tmp_name'])) {
+ return "Error: missing tmp_name";
+ }
+ if (!is_uploaded_file($data['tmp_name'])) {
+ return "Error: tmp_name may not be uploaded";
}
$p = s2p($ref);
if ($max_file_size > 0 &&
filesize($r_path) + filesize($w_path) > $max_file_size * 1024 * 1024) {
jirafeau_async_delete($ref);
- return 'Error';
+ return "Error: file size is above upload limit";
}
/* Concatenate data. */
fclose($r);
fclose($w);
jirafeau_async_delete($ref);
- return 'Error';
+ return "Error: cannot write file";
}
}
fclose($r);
}
/**
- * Finalyze an asynchronous upload.
+ * Finalize an asynchronous upload.
* @param $ref asynchronous upload reference
* @param $code client code for this operation
* @param $crypt boolean asking to crypt or not
* @param $link_name_length link name length
- * @return a string containing the download reference followed by a delete code or the string 'Error'
+ * @return a string containing the download reference followed by a delete code or a string starting with 'Error'
*/
function jirafeau_async_end($ref, $code, $crypt, $link_name_length, $file_hash_method)
{
$a = jirafeau_get_async_ref($ref);
if (count($a) == 0
|| $a['next_code'] != "$code") {
- return "Error";
+ return "Error: bad code for ending transfer";
}
/* Generate link infos. */
$p = VAR_ASYNC . s2p($ref) . $ref . "_data";
if (!file_exists($p)) {
- return 'Error';
+ return "Error: referenced file does not exist";
}
$crypted = false;
fclose($handle);
$hash_link = substr(base_16_to_64(md5_file($link_tmp_name)), 0, $link_name_length);
$l = s2p("$hash_link");
- if (!@mkdir(VAR_LINKS . $l, 0755, true) ||
- !rename($link_tmp_name, VAR_LINKS . $l . $hash_link)) {
- return 'Error';
+ if (!@mkdir(VAR_LINKS . $l, 0755, true)) {
+ return "Error: cannot create folder in LINKS";
+ }
+ if (!rename($link_tmp_name, VAR_LINKS . $l . $hash_link)) {
+ return "Error: cannot rename file in LINKS";
}
/* Clean async upload. */