Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 上载文件时出错_Php_Android_Cakephp_File Upload - Fatal编程技术网

Php 上载文件时出错

Php 上载文件时出错,php,android,cakephp,file-upload,Php,Android,Cakephp,File Upload,我想将图像从galery上传到服务器。我成功上传图像,但我只能上传一个文件。如果我上传2个文件,第2个文件将被上传。第一个文件将不会上载。或者,如果我编辑并上传第二个图像文件,则第一个图像文件将被第二个图像文件替换 这是webservicecontroller.php $imagePath = IMAGE_PATH_FOR_TIM_THUMB.'/'.STUDY_MATERIAL_DIR.'/'; if (!empty($_POST)) { $thi

我想将图像从galery上传到服务器。我成功上传图像,但我只能上传一个文件。如果我上传2个文件,第2个文件将被上传。第一个文件将不会上载。或者,如果我编辑并上传第二个图像文件,则第一个图像文件将被第二个图像文件替换

这是webservicecontroller.php

$imagePath      =   IMAGE_PATH_FOR_TIM_THUMB.'/'.STUDY_MATERIAL_DIR.'/';
    if (!empty($_POST))
    {
        $this->loadModel('StudyMaterial');
        if($_POST['type'] != 'delete')
        {
            $shift = array();
            if($_POST['type'] == 'edit')
            {
                $shift['StudyMaterial']['id'] = $_POST['study_material_id'];
            }
            $shift['StudyMaterial']['user_id'] = $_POST['user_id'];
            $shift['StudyMaterial']['standard_id'] = $_POST['standard_id'];
            $shift['StudyMaterial']['subject_id'] = $_POST['subject_id'];
            $shift['StudyMaterial']['topic_id'] = $_POST['topic_id'];
            $shift['StudyMaterial']['lesson_id'] = $_POST['lesson_id'];
            $shift['StudyMaterial']['name'] = $_POST['name'];
            $shift['StudyMaterial']['description'] = $_POST['description'];

            $this->StudyMaterial->save($shift);
            $study_material_id = $this->StudyMaterial->id;

            if(isset($_FILES['study_material_file']) && !empty($_FILES['study_material_file']) && ($_FILES['study_material_file']['error'] == 0))
            {
                $name = $_FILES['study_material_file']['name'];
                $ext = substr(strrchr($name, "."), 1);
                $only_name = $name . "_" . time();
                $filename = 'topic_file_'.microtime(true).'.'.strtolower($ext);
                $original = STUDY_MATERIAL_DIR . "/" . $filename;
                $file_type = $_POST['file_type'];           
                if($file_type == 'video')
                {
                    if(strtolower($ext) == 'mov')
                    {
                        $original = STUDY_MATERIAL_DIR . "/" . $filename;
                        @move_uploaded_file($_FILES["study_material_file"]["tmp_name"], $original);
                        $new_filename = $only_name. '.mp4';
                        $srcFile = STUDY_MATERIAL_DIR . "/" . $filename;
                        $destFile = STUDY_MATERIAL_DIR . "/" . $new_filename;                   
                        exec('ffmpeg -i '.$srcFile.' -f mp4 -s 320x240 '.$destFile.'');         
                        if($_POST['type'] == 'edit')
                        {
                            $checkAlready   =   $this->StudyMaterial->find('first',array('conditions'=>array('StudyMaterial.id'=>$_POST['study_material_id'])));        
                            $image = $checkAlready['StudyMaterial']['file_name']; 
                            if($image &&  file_exists(WWW_ROOT.STUDY_MATERIAL_DIR.DS.$image )) 
                            {
                                @unlink(WWW_ROOT.STUDY_MATERIAL_DIR.DS.$image);
                            }
                        }
                        $this->StudyMaterial->saveField('file_name',$filename,false);
                        $this->StudyMaterial->saveField('type',$file_type,false);
                    }
                    else
                    {
                        @move_uploaded_file($_FILES["study_material_file"]["tmp_name"], $original);
                        if($_POST['type'] == 'edit')
                        {
                            $checkAlready   =   $this->StudyMaterial->find('first',array('conditions'=>array('StudyMaterial.id'=>$_POST['study_material_id'])));        
                            $image = $checkAlready['StudyMaterial']['file_name']; 
                            if($image &&  file_exists(WWW_ROOT.STUDY_MATERIAL_DIR.DS.$image )) 
                            {
                                @unlink(WWW_ROOT.STUDY_MATERIAL_DIR.DS.$image);
                            }
                        }
                        $this->StudyMaterial->saveField('file_name',$filename,false);
                        $this->StudyMaterial->saveField('type',$file_type,false);
                    }
                }
                else
                {           
                    @move_uploaded_file($_FILES["study_material_file"]["tmp_name"], $original);
                    if($_POST['type'] == 'edit')
                    {
                        $checkAlready   =   $this->StudyMaterial->find('first',array('conditions'=>array('StudyMaterial.id'=>$_POST['study_material_id'])));        
                        $image = $checkAlready['StudyMaterial']['file_name']; 
                        if($image &&  file_exists(WWW_ROOT.STUDY_MATERIAL_DIR.DS.$image )) 
                        {
                            @unlink(WWW_ROOT.STUDY_MATERIAL_DIR.DS.$image);
                        }
                    }
                    $this->StudyMaterial->saveField('file_name',$filename,false);
                    $this->StudyMaterial->saveField('type',$file_type,false);
                }
            }
            else
            {
                if($_POST['type'] == 'edit')
                {
                    $this->StudyMaterial->id = $_POST['study_material_id'];
                    $this->StudyMaterial->saveField('file_name','',false);
                    $this->StudyMaterial->saveField('type','',false);
                }                   
            }
            if($_POST['type'] == 'edit')
            {
                $responseData =   array(
                    'status' =>  1,
                    'message' =>  "Study Material updated successfully."
                );
            }
            else
            {
                $responseData =   array(
                    'status' =>  1,
                    'message' =>  "Study Material added successfully."
                );
            }
        }
问题出在webservice还是android?这是add_material.java

private void selectImage() {

    Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    intent.setType("image/*");
    getActivity().startActivityForResult(Intent.createChooser(intent, "Select File"), SELECT_FILE);
}

public String getRealPathFromURI(Uri contentUri) {
    String[] proj = {MediaStore.Images.Media.DATA};
    Cursor cursor = getActivity().managedQuery(contentUri, proj, null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    return cursor.getString(column_index);
}

服务器端出现问题,请在更新列的位置检查数据库查询。

我已检查了数据库,列是正确的。如何在不替换以前图像的情况下上载文件图像?我认为每次在服务器上上载图像时都使用相同的名称。在服务器上上载图像时使用不同的名称是因为@unlink函数吗?如果(file_exists('your-filename.ext')){chmod('your-filename.ext',0755);unlink('your-filename');}移动已上载的文件($_FILES['image']['tmp_name'],'your filename');没有上载代码。那么我们能说什么呢?不清楚您是一次上载两个文件还是一个文件接着一个文件。