real_connect($conf->hostname,$conf->username,$conf->password,
$conf->database);
$upload_dir = '/home/ncaguild/nca-guild.com/screens/uploads/';
$uploads = scandir($upload_dir);
$imports = array();
$failed = 0;
foreach($uploads as $upload) {
$current = array(
'old' => $upload,
);
if(preg_match('/^([0-9]+)(\..*)/', $upload, $matches) == 0) {
$current['error'] = 'File is not in screens format';
$imports[] = $current;
$failed++;
continue;
}
$id = $matches[1];
$extension = $matches[2];
$size = getimagesize($upload_dir . $upload);
$width = $size[0];
$height = $size[1];
$file_size = filesize($upload_dir . $upload) / 1024;
$hash = md5_file($upload_dir . $upload);
$duplicate = check_duplicate($hash);
if($file_size > 2048) {
$current['error'] = 'File size exceeds 2048kb';
$imports[] = $current;
$failed++;
continue;
}
if(preg_match('/(gif|jpg|jpeg|png|bmp)/',$upload) == 0) {
$current['error'] = 'File extension not supported';
$imports[] = $current;
$failed++;
continue;
}
if($duplicate) {
$current['error'] = 'File is a duplicate: ' . $id;
$imports[] = $current;
$failed++;
continue;
}
$query = $db->prepare("INSERT INTO uploads (id,extension,original_name,width,height,size,hash) VALUES(?,?,?.?.?.?)");
$query->bind_param('isssiids',$id, $extension, 'unknown', $width, $height, $size, $hash);
$query->execute();
$query->close();
$current['height'] = $height;
$current['width'] = $width;
$current['file_size'] = $file_size;
$current['hash'] = $hash;
$current['extension'] = $extension;
$imports[] = $current;
}
function check_duplicate($hash) {
// code incoming
return false;
}
?>
Total Imports: ( failed)
File Name | Dimensions | File Size | Hash | Extension | ||||
---|---|---|---|---|---|---|---|---|
x | kb |