示例#1
0
function sendFile($filename)
{
    $suffix = pathinfo($filename, PATHINFO_EXTENSION);
    $size = filesize_unlimited($filename);
    header('Content-Transfer-Encoding: binary');
    header('Content-Disposition: attachment; filename="' . mb_basename($filename) . '"');
    header('Content-Type: ' . get_mime_type($filename, $suffix));
    header('Content-Length: ' . $size);
    header("Content-Type: application/octet-stream");
    ob_end_flush();
    readfile($filename);
}
示例#2
0
     }
     if (strlen($origfile) > 0) {
         # do an extra check to see if the original filename might have uppercase extension that can be preserved.
         $pathparts = pathinfo($origfile);
         if (isset($pathparts['extension'])) {
             if (strtolower($pathparts['extension']) == $ext) {
                 $ext = $pathparts['extension'];
             }
         }
         # Use the original filename if one has been set.
         # Strip any path information (e.g. if the staticsync.php is used).
         # append preview size to base name if not the original
         if ($size != "") {
             $filename = strip_extension(mb_basename($origfile)) . "-" . $size . "." . $ext;
         } else {
             $filename = strip_extension(mb_basename($origfile)) . "." . $ext;
         }
         if ($prefix_resource_id_to_filename) {
             $filename = $prefix_filename_string . $ref . "_" . $filename;
         }
     }
 }
 if ($download_filename_id_only) {
     if (!hook('customdownloadidonly', '', array($ref, $ext, $alternative))) {
         $filename = $ref . "." . $ext;
     }
 }
 if (isset($download_filename_field)) {
     $newfilename = get_data_by_field($ref, $download_filename_field);
     if ($newfilename) {
         $filename = trim(nl2br(strip_tags($newfilename)));
示例#3
0
 /**
  * 日本語ファイル名対応版basename
  */
 public function testMb_basename()
 {
     $result = mb_basename('/hoge/あいうえお.php');
     $this->assertEquals('あいうえお.php', $result);
     $result = mb_basename('/hoge/あいうえお.phptest', 'test');
     $this->assertEquals('あいうえお.php', $result, 'suffixを取り除けません');
     $result = mb_basename('/hoge/あいうえおtest.php', 'test');
     $this->assertEquals('あいうえおtest.php', $result);
 }
示例#4
0
 public function savefile($uid, $original_file_path, $original_basename, $file_name = NULL, $file_ext = NULL, $description = NULL)
 {
     if (!file_exists($original_file_path)) {
         return FALSE;
     }
     is_null($file_ext) && ($file_ext = strtolower(pathinfo($original_basename, PATHINFO_EXTENSION)));
     is_null($file_name) && ($file_name = mb_basename($original_basename, '.' . $file_ext));
     //支持中文的basename
     $size = filesize($original_file_path);
     if (!in_array($file_ext, $this->_config['ext'])) {
         return static::UPLOAD_ERR_EXT;
     }
     if ($size > $this->_config['maxsize']) {
         return static::UPLOAD_ERR_MAXSIZE;
     }
     if (empty($size)) {
         return static::UPLOAD_ERR_EMPTY;
     }
     //传文件都耗费了那么多时间,还怕md5?
     $hash = md5_file($original_file_path);
     $file = $this->fileModel->get_byhash($hash, $size);
     if (empty($file)) {
         $new_basename = $this->_get_hash_basename();
         $new_hash_path = $this->get_hash_path($new_basename);
         if (!$this->_save_file($original_file_path, $new_basename)) {
             return static::UPLOAD_ERR_SAVE;
         }
         $file = AttachmentFile::create(['basename' => $new_basename, 'path' => $new_hash_path, 'hash' => $hash, 'size' => $size]);
     } else {
         //已经存在此文件
         @unlink($original_file_path);
     }
     $attachment = $this->create(['afid' => $file->getKey(), 'filename' => $file_name, 'ext' => $file_ext, 'original_basename' => $original_basename, 'description' => $description, 'uid' => $uid]);
     //当前Model更新
     //$this->setRawAttributes($attachment->getAttributes(), true);
     return $this->get($attachment->getKey());
 }
示例#5
0
function basepagename($str)
{
    return mb_basename($str);
}
                } else {
                    $previewstatus .= "<br/><br/>";
                }
                ?>
<script type="text/javascript">document.getElementById('uploadlog').innerHTML+="<?php 
                echo $previewstatus;
                ?>
";</script><?php 
                flush();
            }
            // Test if thumbnail creation is allowed during upload
            # Store original filename in field, if set
            if (isset($filename_field)) {
                $filename = $uploadfiles[$n];
                if ($use_local) {
                    $filename = mb_basename($filename);
                }
                update_field($ref, $filename_field, $filename);
            }
            # get file metadata
            if (getval("no_exif", "") == "") {
                extract_exif_comment($ref, $extension);
            }
            # extract text from documents (e.g. PDF, DOC).
            global $extracted_text_field;
            if (isset($extracted_text_field) && !$no_exif) {
                extract_text($ref, $extension);
            }
            $done++;
            # Add to collection?
            if ($collection != "") {
function extract_exif_comment($ref, $extension = "")
{
    # Extract the EXIF comment from either the ImageDescription field or the UserComment
    # Also parse IPTC headers and insert
    # EXIF headers
    $exifoption = getval("no_exif", "");
    // This may have been set to a non-standard value if allowing per field selection
    if ($exifoption == "yes") {
        $exifoption = "no";
    }
    // Sounds odd but previously was no_exif so logic reversed
    if ($exifoption == "") {
        $exifoption = "yes";
    }
    $image = get_resource_path($ref, true, "", false, $extension);
    if (!file_exists($image)) {
        return false;
    }
    hook("pdfsearch");
    global $exif_comment, $exiftool_no_process, $exiftool_resolution_calc, $disable_geocoding, $embedded_data_user_select_fields, $filename_field;
    $exiftool_fullpath = get_utility_path("exiftool");
    if ($exiftool_fullpath != false && !in_array($extension, $exiftool_no_process)) {
        $resource = get_resource_data($ref);
        # Field 8 is used in a special way for staticsync; don't overwrite.
        if ($resource['file_path'] != "") {
            $omit_title_for_staticsync = true;
        } else {
            $omit_title_for_staticsync = false;
        }
        hook("beforeexiftoolextraction");
        if ($exiftool_resolution_calc) {
            # see if we can use exiftool to get resolution/units, and dimensions here.
            # Dimensions are normally extracted once from the view page, but for the original file, it should be done here if possible,
            # and exiftool can provide more data.
            $command = $exiftool_fullpath . " -s -s -s -t -composite:imagesize -xresolution -resolutionunit " . escapeshellarg($image);
            $dimensions_resolution_unit = explode("\t", run_command($command));
            # if dimensions resolution and unit could be extracted, add them to the database.
            # they can be used in view.php to give more accurate data.
            if (count($dimensions_resolution_unit) == 3) {
                $dru = $dimensions_resolution_unit;
                $filesize = filesize_unlimited($image);
                $wh = explode("x", $dru[0]);
                $width = $wh[0];
                $height = $wh[1];
                $resolution = $dru[1];
                $unit = $dru[2];
                sql_query("insert into resource_dimensions (resource, width, height, resolution, unit, file_size) values ('{$ref}', '{$width}', '{$height}', '{$resolution}', '{$unit}', '{$filesize}')");
            }
        }
        $read_from = get_exiftool_fields($resource['resource_type']);
        # run exiftool to get all the valid fields. Use -s -s option so that
        # the command result isn't printed in columns, which will help in parsing
        # We then split the lines in the result into an array
        $command = $exiftool_fullpath . " -s -s -f -m -d \"%Y-%m-%d %H:%M:%S\" -G " . escapeshellarg($image);
        $metalines = explode("\n", run_command($command));
        $metadata = array();
        # an associative array to hold metadata field/value pairs
        # go through each line and split field/value using the first
        # occurrance of ": ".  The keys in the associative array is converted
        # into uppercase for easier lookup later
        foreach ($metalines as $metaline) {
            # Use stripos() if available, but support earlier PHP versions if not.
            if (function_exists("stripos")) {
                $pos = stripos($metaline, ": ");
            } else {
                $pos = strpos($metaline, ": ");
            }
            if ($pos) {
                # add to the associative array, also clean up leading/trailing space & single quote (on windows sometimes)
                # Extract group name and tag name.
                $s = explode("]", substr($metaline, 0, $pos));
                if (count($s) > 1 && strlen($s[0]) > 1) {
                    # Extract value
                    $value = trim(substr($metaline, $pos + 2));
                    # Replace '..' with line feed - either Exiftool itself or Adobe Bridge replaces line feeds with '..'
                    $value = str_replace('....', '\\n\\n', $value);
                    // Two new line feeds in ExifPro are replaced with 4 dots '....'
                    $value = str_replace('...', '.\\n', $value);
                    # Three dots together is interpreted as a full stop then line feed, not the other way round
                    $value = str_replace('..', '\\n', $value);
                    # Extract group name and tag name
                    $groupname = strtoupper(substr($s[0], 1));
                    $tagname = strtoupper(trim($s[1]));
                    # Store both tag data under both tagname and groupname:tagname, to support both formats when mapping fields.
                    $metadata[$tagname] = $value;
                    $metadata[$groupname . ":" . $tagname] = $value;
                    debug("Exiftool: extracted field '{$groupname}:{$tagname}', value is '{$value}'");
                }
            }
        }
        // We try to fetch the original filename from database.
        $resources = sql_query("SELECT resource.file_path FROM resource WHERE resource.ref = " . $ref);
        if ($resources) {
            $resource = $resources[0];
            if ($resource['file_path']) {
                $metadata['FILENAME'] = mb_basename($resource['file_path']);
            }
        }
        if (isset($metadata['FILENAME'])) {
            $metadata['STRIPPEDFILENAME'] = strip_extension($metadata['FILENAME']);
        }
        # Geolocation Metadata Support
        if (!$disable_geocoding && isset($metadata['GPSLATITUDE'])) {
            # Set vars
            $dec_long = 0;
            $dec_lat = 0;
            #Convert latititude to decimal.
            if (preg_match("/^(?<degrees>\\d+) deg (?<minutes>\\d+)' (?<seconds>\\d+\\.?\\d*)\"/", $metadata['GPSLATITUDE'], $latitude)) {
                $dec_lat = $latitude['degrees'] + $latitude['minutes'] / 60 + $latitude['seconds'] / (60 * 60);
            }
            if (preg_match("/^(?<degrees>\\d+) deg (?<minutes>\\d+)' (?<seconds>\\d+\\.?\\d*)\"/", $metadata['GPSLONGITUDE'], $longitude)) {
                $dec_long = $longitude['degrees'] + $longitude['minutes'] / 60 + $longitude['seconds'] / (60 * 60);
            }
            if (strpos($metadata['GPSLATITUDE'], 'S') !== false) {
                $dec_lat = -1 * $dec_lat;
            }
            if (strpos($metadata['GPSLONGITUDE'], 'W') !== false) {
                $dec_long = -1 * $dec_long;
            }
            if ($dec_long != 0 && $dec_lat != 0) {
                sql_query("update resource set geo_long='" . escape_check($dec_long) . "',geo_lat='" . escape_check($dec_lat) . "' where ref='{$ref}'");
            }
        }
        # Update portrait_landscape_field (when reverting metadata this was getting lost)
        update_portrait_landscape_field($ref);
        # now we lookup fields from the database to see if a corresponding value
        # exists in the uploaded file
        $exif_updated_fields = array();
        for ($i = 0; $i < count($read_from); $i++) {
            $field = explode(",", $read_from[$i]['exiftool_field']);
            foreach ($field as $subfield) {
                $subfield = strtoupper($subfield);
                // convert to upper case for easier comparision
                if (in_array($subfield, array_keys($metadata)) && $metadata[$subfield] != "-" && trim($metadata[$subfield]) != "") {
                    $read = true;
                    $value = $metadata[$subfield];
                    # Dropdown box or checkbox list?
                    if ($read_from[$i]["type"] == 2 || $read_from[$i]["type"] == 3) {
                        # Check that the value is one of the options and only insert if it is an exact match.
                        # The use of safe_file_name and strtolower ensures matching takes place on alphanumeric characters only and ignores case.
                        # First fetch all options in all languages
                        $options = trim_array(explode(",", strtolower($read_from[$i]["options"])));
                        for ($n = 0; $n < count($options); $n++) {
                            $options[$n] = $options[$n];
                        }
                        # If not in the options list, do not read this value
                        $s = trim_array(explode(",", $value));
                        $value = "";
                        # blank value
                        for ($n = 0; $n < count($s); $n++) {
                            if (trim($s[0]) != "" && in_array(strtolower($s[$n]), $options)) {
                                $value .= "," . $s[$n];
                            }
                        }
                        #echo($read_from[$i]["ref"] . " = " . $value . "<br>");
                    }
                    # Read the data.
                    if ($read) {
                        $plugin = dirname(__FILE__) . "/../plugins/exiftool_filter_" . $read_from[$i]['name'] . ".php";
                        if ($read_from[$i]['exiftool_filter'] != "") {
                            eval($read_from[$i]['exiftool_filter']);
                        }
                        if (file_exists($plugin)) {
                            include $plugin;
                        }
                        # Field 8 is used in a special way for staticsync; don't overwrite field 8 in this case
                        if (!($omit_title_for_staticsync && $read_from[$i]['ref'] == 8)) {
                            $exiffieldoption = $exifoption;
                            if ($exifoption == "custom" || isset($embedded_data_user_select_fields) && in_array($read_from[$i]['ref'], $embedded_data_user_select_fields)) {
                                debug("EXIF - custom option for field " . $read_from[$i]['ref'] . " : " . $exifoption);
                                $exiffieldoption = getval("exif_option_" . $read_from[$i]['ref'], $exifoption);
                            }
                            debug("EXIF - option for field " . $read_from[$i]['ref'] . " : " . $exiffieldoption);
                            if ($exiffieldoption == "no") {
                                continue;
                            } elseif ($exiffieldoption == "append") {
                                $spacechar = $read_from[$i]["type"] == 2 || $read_from[$i]["type"] == 3 ? ", " : " ";
                                $oldval = get_data_by_field($ref, $read_from[$i]['ref']);
                                if (strpos($oldval, $value) !== false) {
                                    continue;
                                }
                                $newval = $oldval . $spacechar . iptc_return_utf8($value);
                            } elseif ($exiffieldoption == "prepend") {
                                $spacechar = $read_from[$i]["type"] == 2 || $read_from[$i]["type"] == 3 ? ", " : " ";
                                $oldval = get_data_by_field($ref, $read_from[$i]['ref']);
                                if (strpos($oldval, $value) !== false) {
                                    continue;
                                }
                                $newval = iptc_return_utf8($value) . $spacechar . $oldval;
                            } else {
                                $newval = iptc_return_utf8($value);
                            }
                            global $merge_filename_with_title, $lang;
                            if ($merge_filename_with_title) {
                                $merge_filename_with_title_option = urlencode(getval('merge_filename_with_title_option', ''));
                                $merge_filename_with_title_include_extensions = urlencode(getval('merge_filename_with_title_include_extensions', ''));
                                $merge_filename_with_title_spacer = urlencode(getval('merge_filename_with_title_spacer', ''));
                                $original_filename = '';
                                if (isset($_REQUEST['name'])) {
                                    $original_filename = $_REQUEST['name'];
                                } else {
                                    $original_filename = $processfile['name'];
                                }
                                if ($merge_filename_with_title_include_extensions == 'yes') {
                                    $merged_filename = $original_filename;
                                } else {
                                    $merged_filename = strip_extension($original_filename);
                                }
                                $oldval = get_data_by_field($ref, $read_from[$i]['ref']);
                                if (strpos($oldval, $value) !== FALSE) {
                                    continue;
                                }
                                switch ($merge_filename_with_title_option) {
                                    case $lang['merge_filename_title_do_not_use']:
                                        // Do nothing since the user doesn't want to use this feature
                                        break;
                                    case $lang['merge_filename_title_replace']:
                                        $newval = $merged_filename;
                                        break;
                                    case $lang['merge_filename_title_prefix']:
                                        $newval = $merged_filename . $merge_filename_with_title_spacer . $oldval;
                                        if ($oldval == '') {
                                            $newval = $merged_filename;
                                        }
                                        break;
                                    case $lang['merge_filename_title_suffix']:
                                        $newval = $oldval . $merge_filename_with_title_spacer . $merged_filename;
                                        if ($oldval == '') {
                                            $newval = $merged_filename;
                                        }
                                        break;
                                    default:
                                        // Do nothing
                                        break;
                                }
                            }
                            update_field($ref, $read_from[$i]['ref'], $newval);
                            $exif_updated_fields[] = $read_from[$i]['ref'];
                            hook("metadata_extract_addition", "all", array($ref, $newval, $read_from, $i));
                        }
                    }
                } else {
                    // Process if no embedded title is found:
                    global $merge_filename_with_title, $lang;
                    if ($merge_filename_with_title && $read_from[$i]['ref'] == 8) {
                        $merge_filename_with_title_option = urlencode(getval('merge_filename_with_title_option', ''));
                        $merge_filename_with_title_include_extensions = urlencode(getval('merge_filename_with_title_include_extensions', ''));
                        $merge_filename_with_title_spacer = urlencode(getval('merge_filename_with_title_spacer', ''));
                        $original_filename = '';
                        if (isset($_REQUEST['name'])) {
                            $original_filename = $_REQUEST['name'];
                        } else {
                            $original_filename = $processfile['name'];
                        }
                        if ($merge_filename_with_title_include_extensions == 'yes') {
                            $merged_filename = $original_filename;
                        } else {
                            $merged_filename = strip_extension($original_filename);
                        }
                        $oldval = get_data_by_field($ref, $read_from[$i]['ref']);
                        if (strpos($oldval, $value) !== FALSE) {
                            continue;
                        }
                        switch ($merge_filename_with_title_option) {
                            case $lang['merge_filename_title_do_not_use']:
                                // Do nothing since the user doesn't want to use this feature
                                break;
                            case $lang['merge_filename_title_replace']:
                                $newval = $merged_filename;
                                break;
                            case $lang['merge_filename_title_prefix']:
                                $newval = $merged_filename . $merge_filename_with_title_spacer . $oldval;
                                if ($oldval == '') {
                                    $newval = $merged_filename;
                                }
                                break;
                            case $lang['merge_filename_title_suffix']:
                                $newval = $oldval . $merge_filename_with_title_spacer . $merged_filename;
                                if ($oldval == '') {
                                    $newval = $merged_filename;
                                }
                                break;
                            default:
                                // Do nothing
                                break;
                        }
                        update_field($ref, $read_from[$i]['ref'], $newval);
                        $exif_updated_fields[] = $read_from[$i]['ref'];
                    }
                }
            }
        }
        if (!in_array($filename_field, $exif_updated_fields)) {
            $exiffilenameoption = getval("exif_option_" . $filename_field, $exifoption);
            debug("EXIF - custom option for filename field " . $filename_field . " : " . $exiffilenameoption);
            if ($exiffilenameoption != "yes") {
                $uploadedfilename = isset($_REQUEST['name']) ? $_REQUEST['name'] : $processfile['name'];
                global $userref, $amended_filename;
                $entered_filename = get_data_by_field(-$userref, $filename_field);
                debug("EXIF - got entered file name " . $entered_filename);
                if ($exiffilenameoption == "no") {
                    $amended_filename = $entered_filename;
                    if (trim($amended_filename) == '') {
                        $amended_filename = $uploadedfilename;
                    }
                    if (strpos($amended_filename, $extension) === FALSE) {
                        $amended_filename .= '.' . $extension;
                    }
                } elseif ($exiffilenameoption == "append") {
                    $amended_filename = $entered_filename . $uploadedfilename;
                } elseif ($exiffilenameoption == "prepend") {
                    $amended_filename = strip_extension($uploadedfilename) . $entered_filename . "." . $extension;
                }
                debug("EXIF - created new file name " . $amended_filename);
            }
        }
    } elseif (isset($exif_comment)) {
        #
        # Exiftool is not installed. As a fallback we grab some predefined basic fields using the PHP function
        # exif_read_data()
        #
        if (function_exists("exif_read_data")) {
            $data = @exif_read_data($image);
        } else {
            $data = false;
        }
        if ($data !== false) {
            $comment = "";
            #echo "<pre>EXIF\n";print_r($data);exit();
            if (isset($data["ImageDescription"])) {
                $comment = $data["ImageDescription"];
            }
            if ($comment == "" && isset($data["COMPUTED"]["UserComment"])) {
                $comment = $data["COMPUTED"]["UserComment"];
            }
            if ($comment != "") {
                # Convert to UTF-8
                $comment = iptc_return_utf8($comment);
                # Save comment
                global $exif_comment;
                update_field($ref, $exif_comment, $comment);
            }
            if (isset($data["Model"])) {
                # Save camera make/model
                global $exif_model;
                update_field($ref, $exif_model, $data["Model"]);
            }
            if (isset($data["DateTimeOriginal"])) {
                # Save camera date/time
                global $exif_date;
                $date = $data["DateTimeOriginal"];
                # Reformat date to ISO standard
                $date = substr($date, 0, 4) . "-" . substr($date, 5, 2) . "-" . substr($date, 8, 11);
                update_field($ref, $exif_date, $date);
            }
        }
        # Try IPTC headers
        $size = getimagesize($image, $info);
        if (isset($info["APP13"])) {
            $iptc = iptcparse($info["APP13"]);
            #echo "<pre>IPTC\n";print_r($iptc);exit();
            # Look for iptc fields, and insert.
            $fields = sql_query("select * from resource_type_field where length(iptc_equiv)>0");
            for ($n = 0; $n < count($fields); $n++) {
                $iptc_equiv = $fields[$n]["iptc_equiv"];
                if (isset($iptc[$iptc_equiv][0])) {
                    # Found the field
                    if (count($iptc[$iptc_equiv]) > 1) {
                        # Multiple values (keywords)
                        $value = "";
                        for ($m = 0; $m < count($iptc[$iptc_equiv]); $m++) {
                            if ($m > 0) {
                                $value .= ", ";
                            }
                            $value .= $iptc[$iptc_equiv][$m];
                        }
                    } else {
                        $value = $iptc[$iptc_equiv][0];
                    }
                    $value = iptc_return_utf8($value);
                    # Date parsing
                    if ($fields[$n]["type"] == 4) {
                        $value = substr($value, 0, 4) . "-" . substr($value, 4, 2) . "-" . substr($value, 6, 2);
                    }
                    if (trim($value) != "") {
                        update_field($ref, $fields[$n]["ref"], $value);
                    }
                }
            }
        }
    }
    # Update the XML metadata dump file.
    update_xml_metadump($ref);
    # Auto fill any blank fields.
    autocomplete_blank_fields($ref);
}
示例#8
0
文件: funcs.php 项目: dg-wfk/dl
function mb_sane_base($path)
{
    $base = mb_basename($path);
    return mb_sanitize(mb_strlen($base) ? $base : $path);
}
示例#9
0
 /**
  * ファイルへのリンクを取得する
  *
  * @param string $fieldName
  * @param array $options
  * @return string
  */
 public function fileLink($fieldName, $options = array())
 {
     $options = array_merge(array('imgsize' => 'medium', 'rel' => '', 'title' => '', 'link' => true, 'force' => false, 'width' => '', 'height' => ''), $options);
     extract($options);
     if (strpos($fieldName, '.') === false) {
         throw new BcException('BcUploadHelper を利用するには、$fieldName に、モデル名とフィールド名をドットで区切って指定する必要があります。');
     }
     $this->setEntity($fieldName);
     $field = $this->field();
     $tmp = false;
     $Model = ClassRegistry::init($this->model());
     try {
         $settings = $this->getBcUploadSetting();
     } catch (BcException $e) {
         throw $e;
     }
     $basePath = '/files/' . str_replace(DS, '/', $settings['saveDir']) . '/';
     if (empty($options['value'])) {
         $value = $this->value($fieldName);
     } else {
         $value = $options['value'];
     }
     if (is_array($value)) {
         if (empty($value['session_key']) && empty($value['name'])) {
             $data = $Model->findById($Model->id);
             if (!empty($data[$Model->alias][$field])) {
                 $value = $data[$Model->alias][$field];
             } else {
                 $value = '';
             }
         } else {
             if (isset($value['session_key'])) {
                 $tmp = true;
                 $value = str_replace('/', '_', $value['session_key']);
                 $basePath = '/uploads/tmp/';
             } else {
                 return false;
             }
         }
     }
     /* ファイルのパスを取得 */
     /* 画像の場合はサイズを指定する */
     if (isset($settings['saveDir'])) {
         if ($value && !is_array($value)) {
             $uploadSettings = $settings['fields'][$field];
             $ext = decodeContent('', $value);
             if ($uploadSettings['type'] == 'image' || in_array($ext, $Model->Behaviors->BcUpload->imgExts)) {
                 $options = array('imgsize' => $imgsize, 'rel' => $rel, 'title' => $title, 'link' => $link, 'force' => $force, 'width' => $width, 'height' => $height);
                 if ($tmp) {
                     $options['tmp'] = true;
                 }
                 $fileLinkTag = $this->uploadImage($fieldName, $value, $options) . '<br /><span class="file-name">' . mb_basename($value) . '</span>';
             } else {
                 $filePath = $basePath . $value;
                 $fileLinkTag = $this->Html->link('ダウンロード ≫', $filePath, array('target' => '_blank')) . '<br /><span class="file-name">' . mb_basename($value) . '</span>';
             }
         } else {
             $fileLinkTag = $value;
         }
     } else {
         return false;
     }
     return $fileLinkTag;
 }
示例#10
0
 /**
  * 複数のファイルの存在チェックを行う
  * 
  * @param	string	$fileName
  * @return	array
  * @access	void
  */
 public function filesExists($fileName, $limited = null)
 {
     if (is_null($limited)) {
         $data = $this->find('first', array('conditions' => array('UploaderFile.name' => $fileName), 'recursive' => -1));
         $limited = false;
         if (!empty($data['UploaderFile']['publish_begin']) || !empty($data['UploaderFile']['publish_end'])) {
             $limited = true;
         }
     }
     $pathinfo = pathinfo($fileName);
     $ext = $pathinfo['extension'];
     $basename = mb_basename($fileName, '.' . $ext);
     $files['small'] = $this->fileExists($basename . '__small' . '.' . $ext, $limited);
     $files['midium'] = $this->fileExists($basename . '__midium' . '.' . $ext, $limited);
     $files['large'] = $this->fileExists($basename . '__large' . '.' . $ext, $limited);
     return $files;
 }
 /**
  * アンカータグのリンク先が画像のものをモバイル用に置き換える
  *
  * @param	array	$matches
  * @return	string
  * @access	private
  */
 function __mobileImageAnchorReplace($matches)
 {
     $url = $matches[2];
     $pathinfo = pathinfo($url);
     if (!isset($pathinfo['extension'])) {
         return $matches[0];
     }
     $url = str_replace('__small', '', $url);
     $url = str_replace('__midium', '', $url);
     $url = str_replace('__large', '', $url);
     $basename = mb_basename($url, '.' . $pathinfo['extension']);
     $_url = 'files' . DS . 'uploads' . DS . $basename . '__mobile_large.' . $pathinfo['extension'];
     // TODO uploads固定となってしまっているのでmodelから取得するようにする
     $path = WWW_ROOT . $_url;
     if (file_exists($path)) {
         return '<a' . $matches[1] . 'href="' . $this->BcHtml->webroot($_url) . '"' . $matches[3] . '><img' . $matches[4] . '/></a>';
     } else {
         return $matches[0];
     }
 }