php Codeigniter - 获取上传的文件名

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16345761/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 10:57:11  来源:igfitidea点击:

Codeigniter - get the uploaded file name

phpcodeigniter

提问by Kaloyan Drenski

How can I save my uploaded file's name in a variable (I'm new to CI)?

如何将上传文件的名称保存在变量中(我是 CI 新手)?

I am using this code for testing:

我正在使用此代码进行测试:

I would really appreciate your help on this guys.

我真的很感激你对这些人的帮助。

This is the code I am using (and I am typing this over and over again because of the restrictions of stackoverflow):

这是我正在使用的代码(由于 stackoverflow 的限制,我一遍又一遍地输入):

<?php

class Gallery_model extends CI_Model {

    var $gallery_path;
    var $videos_path;
    var $thumbnail;
    var $video_name;

    function Gallery_model() {

        parent::__construct();

        $this->gallery_path = realpath(APPPATH . '../images');
        $this->videos_path = realpath(APPPATH . '../videos');
        $this->videos_path_tnumb = realpath(APPPATH . '../videos/thumb');

        $this->thumbnail = 'C://xampp//htdocs//upload//videos//thumb';
        $this->video_name = 'C://xampp//htdocs//upload//videos//79825_00_01_SC03_intro.mov';
    }

    function do_upload() {

        $config = array(
//            'allowed_types' => 'jpg|jpeg|png|gif',
//            'upload_path' => $this->gallery_path,
//            'max_size' => 10000

            'allowed_types' => 'avi|mp4|flw|mov',
            'upload_path' => $this->videos_path
        );

        $this->load->library('upload', $config);
        $field_name = "some_field_name";
        if ($this->upload->do_upload()) {
            $this->getThumbImage($_POST['userfile']);
        }
    }

    function getVideoInformation($videoPath) {
        $movie = new ffmpeg_movie($videoPath, false);

        $this->videoDuration = $movie->getDuration();
        $this->frameCount = $movie->getFrameCount();
        $this->frameRate = $movie->getFrameRate();
        $this->videoTitle = $movie->getTitle();
        $this->author = $movie->getAuthor();
        $this->copyright = $movie->getCopyright();
        $this->frameHeight = $movie->getFrameHeight();
        $this->frameWidth = $movie->getFrameWidth();
        $this->pixelFormat = $movie->getPixelFormat();
        $this->bitRate = $movie->getVideoBitRate();
        $this->videoCodec = $movie->getVideoCodec();
        $this->audioCodec = $movie->getAudioCodec();
        $this->hasAudio = $movie->hasAudio();
        $this->audSampleRate = $movie->getAudioSampleRate();
        $this->audBitRate = $movie->getAudioBitRate();
    }

    function getAudioInformation($videoPath) {
        $movie = new ffmpeg_movie($videoPath, false);

        $this->audioDuration = $movie->getDuration();
        $this->frameCount = $movie->getFrameCount();
        $this->frameRate = $movie->getFrameRate();
        $this->audioTitle = $movie->getTitle();
        $this->author = $movie->getAuthor();
        $this->copyright = $movie->getCopyright();
        $this->artist = $movie->getArtist();
        $this->track = $movie->getTrackNumber();
        $this->bitRate = $movie->getBitRate();
        $this->audioChannels = $movie->getAudioChannels();
        $this->audioCodec = $movie->getAudioCodec();
        $this->audSampleRate = $movie->getAudioSampleRate();
        $this->audBitRate = $movie->getAudioBitRate();
    }

    function getThumbImage($videoPath) {
        $movie = new ffmpeg_movie($videoPath, false);
        $this->videoDuration = $movie->getDuration();
        $this->frameCount = $movie->getFrameCount();
        $this->frameRate = $movie->getFrameRate();
        $this->videoTitle = $movie->getTitle();
        $this->author = $movie->getAuthor();
        $this->copyright = $movie->getCopyright();
        $this->frameHeight = $movie->getFrameHeight();
        $this->frameWidth = $movie->getFrameWidth();

        $capPos = ceil($this->frameCount / 4);

        if ($this->frameWidth > 120) {
            $cropWidth = ceil(($this->frameWidth - 120) / 2);
        } else {
            $cropWidth = 0;
        }
        if ($this->frameHeight > 90) {
            $cropHeight = ceil(($this->frameHeight - 90) / 2);
        } else {
            $cropHeight = 0;
        }
        if ($cropWidth % 2 != 0) {
            $cropWidth = $cropWidth - 1;
        }
        if ($cropHeight % 2 != 0) {
            $cropHeight = $cropHeight - 1;
        }

        $frameObject = $movie->getFrame($capPos);


        if ($frameObject) {
            $imageName = "thumb_01.jpeg";
            $tmbPath = "C:\xampp\htdocs\upload\videos\thumb" . $imageName;
            $frameObject->resize(120, 90, 0, 0, 0, 0);
            imagejpeg($frameObject->toGDImage(), $tmbPath);
        } else {
            $imageName = "";
        }


        return $imageName;
    }

}

回答by Elavarasan M Lee

$upload_data = $this->upload->data(); //Returns array of containing all of the data related to the file you uploaded.
$file_name = $upload_data['file_name'];

Read more about it from here for v2.xand here for v3.x.

这里阅读更多关于v2.x 的信息在这里阅读更多关于v3.x 的信息