|
Lines 58-63
use Encode;
Link Here
|
| 58 |
|
58 |
|
| 59 |
use C4::Context; |
59 |
use C4::Context; |
| 60 |
|
60 |
|
|
|
61 |
sub _get_file_path { |
| 62 |
my ($id, $dirname, $filename) = @_; |
| 63 |
|
| 64 |
my $uploadPath = C4::Context->preference('uploadPath'); |
| 65 |
my $filepath = "$uploadPath/$dirname/${id}_$filename"; |
| 66 |
$filepath =~ s|/+|/|g; |
| 67 |
|
| 68 |
return $filepath; |
| 69 |
} |
| 70 |
|
| 61 |
=head2 GetUploadedFile |
71 |
=head2 GetUploadedFile |
| 62 |
|
72 |
|
| 63 |
my $file = C4::UploadedFiles::GetUploadedFile($id); |
73 |
my $file = C4::UploadedFiles::GetUploadedFile($id); |
|
Lines 93-98
sub GetUploadedFile {
Link Here
|
| 93 |
my $sth = $dbh->prepare($query); |
103 |
my $sth = $dbh->prepare($query); |
| 94 |
$sth->execute($id); |
104 |
$sth->execute($id); |
| 95 |
my $file = $sth->fetchrow_hashref; |
105 |
my $file = $sth->fetchrow_hashref; |
|
|
106 |
if ($file) { |
| 107 |
$file->{filepath} = _get_file_path($file->{id}, $file->{dir}, |
| 108 |
$file->{filename}); |
| 109 |
} |
| 96 |
|
110 |
|
| 97 |
return $file; |
111 |
return $file; |
| 98 |
} |
112 |
} |
|
Lines 140-152
sub UploadFile {
Link Here
|
| 140 |
|
154 |
|
| 141 |
# Test if this id already exist |
155 |
# Test if this id already exist |
| 142 |
my $file = GetUploadedFile($id); |
156 |
my $file = GetUploadedFile($id); |
| 143 |
if($file) { |
157 |
if ($file) { |
| 144 |
return $file->{id}; |
158 |
return $file->{id}; |
| 145 |
} |
159 |
} |
| 146 |
|
160 |
|
| 147 |
my $upload_path = C4::Context->preference("uploadPath"); |
161 |
my $file_path = _get_file_path($id, $dir, $filename); |
| 148 |
my $file_path = "$upload_path/$dir/$filename"; |
|
|
| 149 |
$file_path =~ s#/+#/#; |
| 150 |
|
162 |
|
| 151 |
my $out_fh; |
163 |
my $out_fh; |
| 152 |
# Create the file only if it doesn't exist |
164 |
# Create the file only if it doesn't exist |
|
Lines 186-194
sub DelUploadedFile {
Link Here
|
| 186 |
|
198 |
|
| 187 |
my $file = GetUploadedFile($id); |
199 |
my $file = GetUploadedFile($id); |
| 188 |
if($file) { |
200 |
if($file) { |
| 189 |
my $upload_path = C4::Context->preference("uploadPath"); |
201 |
my $file_path = $file->{filepath}; |
| 190 |
my $file_path = "$upload_path/$file->{dir}/$file->{filename}"; |
|
|
| 191 |
$file_path =~ s#/+#/#; |
| 192 |
my $file_deleted = 0; |
202 |
my $file_deleted = 0; |
| 193 |
unless( -f $file_path ) { |
203 |
unless( -f $file_path ) { |
| 194 |
warn "Id $file->{id} is in database but not in filesystem, removing id from database"; |
204 |
warn "Id $file->{id} is in database but not in filesystem, removing id from database"; |