-function jirafeau_upload($file, $one_time_download, $key, $time, $cfg, $ip) {
- if(empty($file['tmp_name']) || !is_uploaded_file($file['tmp_name'])) {
- return(array('error' => array('has_error' => true, 'why' => jirafeau_upload_errstr($file['error'])), 'link' => ''));
- }
-
- /* array representing no error */
- $noerr = array('has_error' => false, 'why' => '');
-
- /* file informations */
- $md5 = md5_file($file['tmp_name']);
- $name = trim($file['name']);
- $mime_type = $file['type'];
- $size = $file['size'];
-
- /* does file already exist ? */
- $rc = false;
- if(file_exists(VAR_FILES . $md5)) {
- $rc = unlink($file['tmp_name']);
- }
- elseif(move_uploaded_file($file['tmp_name'], VAR_FILES . $md5)) {
- $rc = true;
- }
- if(!$rc)
- {
- return(array(
- 'error' => array(
- 'has_error' => true,
- 'why' => _('Internal error during file creation.')),
- 'link' => '')
- );
- }
-
- /* increment or create count file */
- $counter=0;
- if(file_exists(VAR_FILES . $md5 . '_count')) {
- $content = file(VAR_FILES . $md5 . '_count');
- $counter = trim($content[0]);
- }
- $counter++;
- $handle = fopen(VAR_FILES . $md5 . '_count', 'w');
- fwrite($handle, $counter);
- fclose($handle);
-
- /* create link file */
- $link_tmp_name = VAR_LINKS . $md5 . rand(0, 10000) . '.tmp';
- $handle = fopen($link_tmp_name, 'w');
- fwrite($handle, $name . NL . $mime_type . NL . $size . NL . $key . NL . $time . NL . $md5 . NL . ($one_time_download ? 'O' : 'R') . NL . date('U') . NL . $ip . NL);
- fclose($handle);
- $md5_link = md5_file($link_tmp_name);
- if(!rename($link_tmp_name, VAR_LINKS . $md5_link)) {
- if ($counter > 1) {
- $counter--;
- $handle = fopen(VAR_FILES . $md5 . '_count', 'w');
- fwrite($handle, $counter);
- fclose($handle);
+function
+jirafeau_upload ($file, $one_time_download, $key, $time, $cfg, $ip)
+{
+ if (empty ($file['tmp_name']) || !is_uploaded_file ($file['tmp_name']))
+ {
+ return (array(
+ 'error' =>
+ array ('has_error' => true,
+ 'why' => jirafeau_upload_errstr ($file['error'])),
+ 'link' => '',
+ 'delete_link' => ''));