Skip to content

Commit 9a59881

Browse files
authored
Merge pull request #300 from Leinad4Mind/acp-import-fix
acp import fix
2 parents 6adf9e0 + 412e0fc commit 9a59881

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

acpimport/acp/main_module.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ function import()
6767
{
6868
$filetype = getimagesize($image_src_full);
6969
$filetype_ext = '';
70+
$file_link = $gallery_url->path('upload') . $image_filename;
7071

7172
$error_occured = false;
7273
switch ($filetype['mime'])
@@ -122,21 +123,19 @@ function import()
122123
}
123124
$image_filename = md5(unique_id()) . $filetype_ext;
124125

125-
if (!$error_occured || !@move_uploaded_file($image_src_full, $gallery_url->path('upload') . $image_filename))
126+
if (!$error_occured || !@move_uploaded_file($image_src_full, $file_link))
126127
{
127-
if (!@copy($image_src_full, $gallery_url->path('upload') . $image_filename))
128+
if (!@copy($image_src_full, $file_link))
128129
{
129130
$user->add_lang('posting');
130-
$this->log_import_error($import_schema, sprintf($user->lang['GENERAL_UPLOAD_ERROR'], $gallery_url->path('upload') . $image_filename));
131+
$this->log_import_error($import_schema, sprintf($user->lang['GENERAL_UPLOAD_ERROR'], $file_link));
131132
$error_occured = true;
132133
}
133134
}
134135

135136
if (!$error_occured)
136137
{
137-
@chmod($gallery_url->path('upload') . $image_filename, 0777);
138-
// The source image is imported, so we delete it.
139-
@unlink($image_src_full);
138+
@chmod($file_link, 0777);
140139

141140
$sql_ary = array(
142141
'image_filename' => $image_filename,
@@ -154,13 +153,11 @@ function import()
154153
//'image_exif_data' => '',
155154
);
156155

157-
unset($image_tools);
158156
$image_tools = $phpbb_container->get('phpbbgallery.core.file.tool');
159157
$image_tools->set_image_options($gallery_config->get('max_filesize'), $gallery_config->get('max_height'), $gallery_config->get('max_width'));
160-
$image_tools->set_image_data($gallery_url->path('upload') . $image_filename);
158+
$image_tools->set_image_data($file_link);
161159

162160
$additional_sql_data = array();
163-
$file_link = $gallery_url->path('upload') . $image_filename;
164161

165162
/**
166163
* Event to trigger before mass update
@@ -176,14 +173,14 @@ function import()
176173
if (($filetype[0] > $gallery_config->get('max_width')) || ($filetype[1] > $gallery_config->get('max_height')))
177174
{
178175
/**
179-
* Resize overside images
176+
* Resize oversize images
180177
*/
181178
if ($gallery_config->get('allow_resize'))
182179
{
183180
$image_tools->resize_image($gallery_config->get('max_width'), $gallery_config->get('max_height'));
184181
if ($image_tools->resized)
185182
{
186-
$image_tools->write_image($gallery_url->path('upload') . $image_filename, $gallery_config->get('jpg_quality'), true);
183+
$image_tools->write_image($file_link, $gallery_config->get('jpg_quality'), true);
187184
}
188185
}
189186
}
@@ -203,7 +200,7 @@ function import()
203200
$sql_ary = array_merge($sql_ary, $additional_sql_data);
204201

205202
// Try to get real filesize from temporary folder (not always working) ;)
206-
$sql_ary['filesize_upload'] = (@filesize($gallery_url->path('upload') . $image_filename)) ? @filesize($gallery_url->path('upload') . $image_filename) : 0;
203+
$sql_ary['filesize_upload'] = (@filesize($file_link)) ? @filesize($file_link) : 0;
207204

208205
if ($filename || ($image_name == ''))
209206
{
@@ -217,6 +214,11 @@ function import()
217214

218215
// Put the images into the database
219216
$db->sql_query('INSERT INTO ' . $table_prefix . 'gallery_images ' . $db->sql_build_array('INSERT', $sql_ary));
217+
// If the source image is imported, we delete it.
218+
if (file_exists($image_src_full))
219+
{
220+
@unlink($image_src_full);
221+
}
220222
}
221223
$done_images++;
222224
}

0 commit comments

Comments
 (0)