示例#1
0
require 'models/user_functions.php';
if (isset($_SESSION)) {
    $emailError = '';
    $imageError = '';
    if (!empty($_POST['newemail'])) {
        $valid = validateEmail($_POST['newemail']);
        if ($valid) {
            $success = updateEmail($_POST['newemail'], $_SESSION['userid']);
            if (!$success) {
                $emailError = 'το E-mail';
            }
        } else {
            $emailError = 'το E-mail';
        }
    }
    if (!empty($_FILES['newimg'])) {
        $path = imageUpload('data/profile_imgs/', 'newimg');
        $success = false;
        if ($path) {
            $success = imageUpdate($path, $_SESSION['userid']);
        }
        if (!$success) {
            $imageError = 'την Εικόνα';
        }
    }
    if ($emailError || $imageError) {
        echo "Προσπαθήστε ξάνα υπήρξε πρόβλημα με : {$emailError} {$imageError} ";
    } else {
        echo 'Ολοκληρώθηκε.';
    }
}
示例#2
0
function imageUpload($flag_flow)
{
    global $cfg, $db;
    authenticate('access_admin', false, true);
    if (ini_get('file_uploads') == false) {
        message(__FILE__, __LINE__, 'error', '[b]Upload error[/b][br]File uploads disabled in the php.ini.');
    }
    if ($_FILES['image_front']['error'] == UPLOAD_ERR_NO_FILE && $_FILES['image_back']['error'] == UPLOAD_ERR_NO_FILE) {
        message(__FILE__, __LINE__, 'error', '[b]Upload error[/b][br]There is no file uploaded');
    }
    if ($_FILES['image_front']['error'] != UPLOAD_ERR_OK && $_FILES['image_front']['error'] != UPLOAD_ERR_NO_FILE) {
        if ($_FILES['image_front']['error'] == UPLOAD_ERR_INI_SIZE) {
            message(__FILE__, __LINE__, 'error', '[b]Upload error[/b][br]The file is larger than the value set in php.ini for upload_max_file');
        } elseif ($_FILES['image_front']['error'] == UPLOAD_ERR_PARTIAL) {
            message(__FILE__, __LINE__, 'error', '[b]Upload error[/b][br]The file is not fully uploaded');
        } elseif ($_FILES['image_front']['error'] == UPLOAD_ERR_NO_TMP_DIR) {
            message(__FILE__, __LINE__, 'error', '[b]Upload error[/b][br]PHP, the directory for the temporary file not found');
        } elseif ($_FILES['image_front']['error'] == UPLOAD_ERR_CANT_WRITE) {
            message(__FILE__, __LINE__, 'error', '[b]Upload error[/b][br]PHP could not write the temporary file');
        } else {
            message(__FILE__, __LINE__, 'error', '[b]Upload error[/b][br]Error code: ' . $_FILES['image_front']['error']);
        }
    }
    if ($_FILES['image_back']['error'] != UPLOAD_ERR_OK && $_FILES['image_back']['error'] != UPLOAD_ERR_NO_FILE) {
        if ($_FILES['image_back']['error'] == UPLOAD_ERR_INI_SIZE) {
            message(__FILE__, __LINE__, 'error', '[b]Upload error[/b][br]The file is larger than the value set in php.ini for upload_max_file');
        } elseif ($_FILES['image_back']['error'] == UPLOAD_ERR_PARTIAL) {
            message(__FILE__, __LINE__, 'error', '[b]Upload error[/b][br]The file is not fully uploaded');
        } elseif ($_FILES['image_back']['error'] == UPLOAD_ERR_NO_TMP_DIR) {
            message(__FILE__, __LINE__, 'error', '[b]Upload error[/b][br]PHP, the directory for the temporary file not found');
        } elseif ($_FILES['image_back']['error'] == UPLOAD_ERR_CANT_WRITE) {
            message(__FILE__, __LINE__, 'error', '[b]Upload error[/b][br]PHP could not write the temporary file');
        } else {
            message(__FILE__, __LINE__, 'error', '[b]Upload error[/b][br]Error code: ' . $_FILES['image_back']['error']);
        }
    }
    $album_id = post('album_id');
    $query = mysql_query('SELECT relative_file FROM track WHERE album_id = "' . mysql_real_escape_string($album_id) . '"');
    $track = mysql_fetch_assoc($query);
    $image_dir = $cfg['media_dir'] . $track['relative_file'];
    $image_dir = substr($image_dir, 0, strrpos($image_dir, '/') + 1);
    if ($track == false) {
        message(__FILE__, __LINE__, 'error', '[b]Error[/b][br]album_id not found in database');
    }
    if ($_FILES['image_front']['error'] == UPLOAD_ERR_OK) {
        $imagesize = @getimagesize($_FILES['image_front']['tmp_name']) or message(__FILE__, __LINE__, 'error', '[b]Upload error[/b][br]Unsupported file.');
        if ($imagesize[2] == IMAGETYPE_JPEG) {
            $image = $image_dir . $cfg['image_front'] . '.jpg';
            $delete = $image_dir . $cfg['image_front'] . '.png';
        } elseif ($imagesize[2] == IMAGETYPE_PNG) {
            $image = $image_dir . $cfg['image_front'] . '.png';
            $delete = $image_dir . $cfg['image_front'] . '.jpg';
        } else {
            message(__FILE__, __LINE__, 'error', '[b]Upload error[/b][br]Unsupported file.');
        }
        if (copy($_FILES['image_front']['tmp_name'], $image) == false) {
            message(__FILE__, __LINE__, 'error', '[b]Failed to copy[/b][br]from: ' . $_FILES['image_front']['tmp_name'] . '[br]to: ' . $image);
        }
        if (is_file($delete) && @unlink($delete) == false) {
            message(__FILE__, __LINE__, 'error', '[b]Failed to delete file:[/b][br]' . $delete);
        }
        $flag = 3;
        // stored
        $filemtime = filemtime($image);
        $filesize = filesize($image);
        $image_id = $album_id . '_' . base_convert(NJB_IMAGE_SIZE * 100 + NJB_IMAGE_QUALITY, 10, 36) . base_convert($filemtime, 10, 36) . base_convert($filesize, 10, 36);
        $relative_image = substr($image, strlen($cfg['media_dir']));
        mysql_query('UPDATE bitmap SET
			image				= "' . mysql_real_escape_string(resampleImage($image)) . '",
			filesize			= ' . (int) $filesize . ',
			filemtime			= ' . (int) $filemtime . ',
			flag				= ' . (int) $flag . ',
			image_front			= "' . mysql_real_escape_string($relative_image) . '",
			image_front_width	= ' . (int) $imagesize[0] . ',
			image_front_height	= ' . (int) $imagesize[1] . ',
			image_id			= "' . mysql_real_escape_string($image_id) . '"
			WHERE album_id		= "' . mysql_real_escape_string($album_id) . '"');
        mysql_query('UPDATE album SET
			image_id			= "' . mysql_real_escape_string($image_id) . '"
			WHERE album_id		= "' . mysql_real_escape_string($album_id) . '"');
    }
    if ($_FILES['image_back']['error'] == UPLOAD_ERR_OK) {
        $imagesize = @getimagesize($_FILES['image_back']['tmp_name']) or message(__FILE__, __LINE__, 'error', '[b]Upload error[/b][br]Unsupported file.');
        if ($imagesize[2] == IMAGETYPE_JPEG) {
            $image = $image_dir . $cfg['image_back'] . '.jpg';
            $delete = $image_dir . $cfg['image_back'] . '.png';
        } elseif ($imagesize[2] == IMAGETYPE_PNG) {
            $image = $image_dir . $cfg['image_back'] . '.png';
            $delete = $image_dir . $cfg['image_back'] . '.jpg';
        } else {
            message(__FILE__, __LINE__, 'error', '[b]Upload error[/b][br]Unsupported file.');
        }
        if (copy($_FILES['image_back']['tmp_name'], $image) == false) {
            message(__FILE__, __LINE__, 'error', '[b]Failed to copy[/b][br]from: ' . $_FILES['image_back']['tmp_name'] . '[br]to: ' . $image);
        }
        if (is_file($delete) && @unlink($delete) == false) {
            message(__FILE__, __LINE__, 'error', '[b]Failed to delete file:[/b][br]' . $delete);
        }
        $relative_image = substr($image, strlen($cfg['media_dir']));
        mysql_query('UPDATE bitmap SET
			image_back			= "' . mysql_real_escape_string($relative_image) . '"
			WHERE album_id		= "' . mysql_real_escape_string($album_id) . '"');
    }
    if ($flag_flow == 9) {
        header('Location: ' . NJB_HOME_URL . 'index.php?action=view3&album_id=' . $album_id);
        exit;
    } else {
        imageUpdate($flag_flow);
    }
}