Exemple #1
0
function upload_image($image_field_name, $dir_path, $sizes)
{
    require_once 'phpthumb/ThumbLib.inc.php';
    $cnt = 1;
    $resized_path = $dir_path;
    if (!file_exists($dir_path)) {
        mkdir($dir_path);
        chmod($dir_path, 0755);
    }
    if (!file_exists($resized_path)) {
        mkdir($resized_path);
        chmod($resized_path, 0755);
    }
    if (!empty($_FILES[$image_field_name]['tmp_name'])) {
        $info = getimagesize($_FILES[$image_field_name]['tmp_name']);
        $originalfilename = basename($_FILES[$image_field_name]['name']);
        $imagetarget = resolve_filename_collisions($dir_path, array(basename($_FILES[$image_field_name]['name'])), $format = '%s_%d.%s');
        $originalfile = $dir_path . $imagetarget[0];
        if (move_uploaded_file($_FILES[$image_field_name]['tmp_name'], $originalfile)) {
            foreach ($sizes as $size) {
                $destinationfile = $resized_path . 'f' . $cnt++ . '_' . $imagetarget[0];
                $thumb = PhpThumbFactory::create($originalfile);
                $thumb->resize($size['width'], $size['height']);
                $thumb->save($destinationfile);
            }
            return $imagetarget[0];
        } else {
            return 0;
        }
    } else {
        return 0;
    }
}
Exemple #2
0
 /**
  * Import an image file encoded in base64 format
  * @param string path path (in course data) to store picture
  * @param string base64 encoded picture
  * @return string filename (nb. collisions are handled)
  */
 function importimagefile($path, $base64)
 {
     global $CFG;
     // all this to get the destination directory
     // and filename!
     $fullpath = "{$CFG->dataroot}/{$this->course->id}/{$path}";
     $path_parts = pathinfo($fullpath);
     $destination = $path_parts['dirname'];
     $file = clean_filename($path_parts['basename']);
     // check if path exists
     check_dir_exists($destination, true, true);
     // detect and fix any filename collision - get unique filename
     $newfiles = resolve_filename_collisions($destination, array($file));
     $newfile = $newfiles[0];
     // convert and save file contents
     if (!($content = base64_decode($base64))) {
         return '';
     }
     $newfullpath = "{$destination}/{$newfile}";
     if (!($fh = fopen($newfullpath, 'w'))) {
         return '';
     }
     if (!fwrite($fh, $content)) {
         return '';
     }
     fclose($fh);
     // return the (possibly) new filename
     $newfile = ereg_replace("{$CFG->dataroot}/{$this->course->id}/", '', $newfullpath);
     return $newfile;
 }
Exemple #3
0
 foreach ($contents as $line) {
     $bits = explode('|', $line, 2);
     // limit set to 2 so we just get filename|decription
     if (count($bits) != 2) {
         // houston, we have a problem!
         echo "Something wrong in manifest file, with line {$line}";
         break 2;
     }
     if (!file_exists($tempdir . '/' . $bits[0])) {
         echo "Manifest file points to " . $bits[0] . " but it doesn't exist!";
         break 2;
     }
     $files[] = $bits[0];
 }
 // rejuggle to handle filename conflicts...
 $files = resolve_filename_collisions($destination, $files);
 // keys should still match, make up the proper data structure...
 foreach ($files as $k => $f) {
     $file = new StdClass();
     $file->filename = $f;
     $line = $contents[$k];
     $bits = explode('|', $line, 2);
     // limit set to 2 so we just get filename|decription
     $file->description = $bits[1];
     $file->originalname = $bits[0];
     $fileinfo[] = $file;
 }
 begin_sql();
 // do it transactionally if we CAN
 // start looking for the database stuff we need....
 $folder = lms_get_folder($installid, $intention->foldername, $user);