Example #1
0
<?php

/*
Jappix - An open social platform
This script (re)generates the store sub-folders (after an update)
-------------------------------------------------
License: AGPL
Authors: Valérian Saliou, regilero
*/
// Someone is trying to hack us?
if (!defined('JAPPIX_BASE')) {
    exit;
}
// Array of the sub-folders to create
$store_folders = array('access', 'backgrounds', 'conf', 'logos', 'music', 'share', 'update');
// Creates the store sub-folders
for ($i = 0; $i < count($store_folders); $i++) {
    $current = JAPPIX_BASE . '/store/' . $store_folders[$i];
    // Create the folder itself
    if (!is_dir($current)) {
        mkdir($current, 0777, true);
    }
    chmod($current, 0777);
    // Create the security file inside the folder
    $security_html = securityHTML();
    file_put_contents($current . '/index.html', $security_html, LOCK_EX);
}
// Apply 777 rights on other writable folders
chmod(JAPPIX_BASE . '/log', 0777);
chmod(JAPPIX_BASE . '/tmp', 0777);
Example #2
0
    $path = $content_dir . '/' . $name . '.' . $ext;
    $thumb_xml = '';
    // Forbidden file?
    if (!isSafe($user) || !isSafeAllowed($filename) || !isSafeAllowed($name . '.' . $ext)) {
        exit('<jappix xmlns=\'jappix:file:post\'>
    <error>forbidden-type</error>
</jappix>');
    }
    // Create the user directory
    if (!is_dir($content_dir)) {
        mkdir($content_dir, 0777, true);
        chmod($content_dir, 0777);
    }
    // Create (or re-create) the security file
    if (!file_exists($security_file)) {
        file_put_contents($security_file, securityHTML(), LOCK_EX);
    }
    // Not already there? (sometimes users upload same file twice, no need to compute it 2 times)
    $file_first_upload = !file_exists($path);
    if ($file_first_upload) {
        // File upload error?
        if (!is_uploaded_file($tmp_filename) || !move_uploaded_file($tmp_filename, $path)) {
            exit('<jappix xmlns=\'jappix:file:post\'>
        <error>move-error</error>
    </jappix>');
        }
    }
    // Resize and compress if this is a JPEG file
    if (preg_match('/^(jpg|jpeg|png|gif)$/i', $ext)) {
        // Image thumbnail path
        $thumb = $content_dir . '/' . $name . '_thumb.' . $ext;
    $path = $content_dir . '/' . $name . '.' . $ext;
    $thumb_xml = '';
    // Forbidden file?
    if (!isSafe($filename) || !isSafe($name . '.' . $ext)) {
        exit('<jappix xmlns=\'jappix:file:post\'>
	<error>forbidden-type</error>
</jappix>');
    }
    // Create the user directory
    if (!is_dir($content_dir)) {
        mkdir($content_dir, 0777, true);
        chmod($content_dir, 0777);
    }
    // Create (or re-create) the security file
    if (!file_exists($security_file)) {
        file_put_contents($security_file, securityHTML());
    }
    // File upload error?
    if (!is_uploaded_file($tmp_filename) || !move_uploaded_file($tmp_filename, $path)) {
        exit('<jappix xmlns=\'jappix:file:post\'>
	<error>move-error</error>
</jappix>');
    }
    // Resize and compress if this is a JPEG file
    if (preg_match('/^(jpg|jpeg|png|gif)$/i', $ext)) {
        // Resize the image
        resizeImage($path, $ext, 1024, 1024);
        // Copy the image
        $thumb = $content_dir . '/' . $name . '_thumb.' . $ext;
        copy($path, $thumb);
        // Create the thumbnail