Código PHP:
function url_upload(){
global $CONFIG, $DB, $UDATA, $file_count, $path, $filename;
for($i = 0; $i <= 15; $i++){
$file = array(
'name' => array_shift(explode('?', basename($_POST['userfile'][$i]))),
'url' => $_POST['userfile'][$i],
'rand' => random_string(20)
);
if($file['name'] != ''){
$file_count++;
if($file_count <= 15){
if($i >= 1){
echo "<div class='cell_divider'></div><br>\n";
}
$extension = file_type($file['name']);
$filename = $file['rand'].".".$extension;
$thumbnail = thumbnail_name($filename);
if(!preg_match("/(https|http|ftp):\/\/[^\"\s']+/", $file['url'])){
message("The file <b>{$file['name']}</b> contains a invalid URL.");
}elseif(!in_array($extension, $CONFIG['file_types'])){
message("The file <b>{$file['name']}</b> extension is not allowed.");
}elseif(!$fcc = implode('', file($file['url']))){
message("The file <b>{$file['name']}</b> is not readable or does not exists.");
}elseif(strlen($fcc) > $CONFIG['max_file_size']){
message("The file <b>{$file['name']}</b> exceeds the max file size allowed.");
}elseif(strlen($fcc) < 5){
message("The file <b>{$file}</b> contains no data.");
}elseif(file_exists(ROOT_PATH.$path.$filename) !== false){
message("The file <b>{$file['name']}</b> seems to already exists on this server.");
}elseif(!fwrite(fopen($path.$filename, 'x'), $fcc)){
message("File transfer failed for file <b>{$file['name']}</b>.");
}else{
if($CONFIG['is_user'] == true){
$DB->query("INSERT INTO `".SQL_FILE_STORAGE_TABLE."` VALUES('', '{$filename}', '0', '{$UDATA['user_id']}');");
}else{
$DB->query("INSERT INTO `".SQL_FILE_STORAGE_TABLE."` VALUES('', '{$filename}', '{$_POST['private']}', '0');");
}
$DB->query("INSERT INTO `".SQL_FILE_LOGS_TABLE."` VALUES ('', '{$filename}', '".time()."', '{$_SERVER['REMOTE_ADDR']}');");
create_thumbnail($filename);
results_table();
}
}
}
}
}