View Full Version : مشکل اپلود
  
googoli
پنج شنبه 10 اردیبهشت 1394, 17:30 عصر
سلام 
من یک فایل می خوام اپلود کنم به کد هام هم به شکل زیر هست 
ولی با ارور زیر مواجه می شم باید چکار کنم 
if (isset($_FILES['Cooperation']))
            {
                $file = $_FILES['Cooperation'] ;
                $extension = explode('.', $file['name']['rezomeh']);
                if(in_array(end($extension), array('docx', 'doc','pdf'))) {
                    if($file['error']['rezomeh'] == 0 && $file['size']['rezomeh'] <= 2097152) {
                        $path = Yii::app()->baseUrl.'/images/Cooperation/';
                        move_uploaded_file($file['tmp_name']['rezomeh'], $path. $file['name']['rezomeh']);
                        echo $path;
                    }
                    
                }
                    
            }
move_uploaded_file(/panel/images/Cooperation/00001.docx): failed to open stream: No such file or directory
دایرکتوری هم با این نام ایجاد کردم و در مسیر موجود هست
desatir7316
پنج شنبه 10 اردیبهشت 1394, 19:16 عصر
اون پیغام خطا که برای آدرس دهی اشتباست ولی در کل چرا از این استفاده نمی کنی؟
http://www.yiiframework.com/wiki/2/
googoli
پنج شنبه 10 اردیبهشت 1394, 20:08 عصر
میشه بگید مشکل ادرس دهیم کجاست ؟
در خصوص لینکی که گذاشتید یه جورایی ازش سر در نیاوردم و همچنین قطعا تا بیام کار کردن باهاش رو یاد بگیرم یه جورایی دیر میشه وقت کم دارم  برای همین استفاده نمی کنم
desatir7316
پنج شنبه 10 اردیبهشت 1394, 21:18 عصر
وقتی که این پیغام رو میده یعنی آدرس دهی مشکل داره :
failed to open stream: No such file or directory
برای ذخیره از basePath استفاده کنید و برای لود کردن از baseUrl
googoli
پنج شنبه 10 اردیبهشت 1394, 22:36 عصر
ممنون از وقتی که گذاشتید
MMSHFE
جمعه 11 اردیبهشت 1394, 11:34 صبح
از امکانات Yii استفاده کنید. اینو تست کنید:
if($file = CUploadedFile::getInstanceByName('Cooperation[rezomeh]')) {
    if(in_array($file->extension, array('docx', 'doc','pdf')) && $file->error == 0 && $file->size <= 2097152) {
        $path = Yii::app()->basePath . '/../images/Cooperation/';
        $file->saveAs($path . $file->name);
        echo $path;
    }
}
googoli
چهارشنبه 23 اردیبهشت 1394, 09:15 صبح
سلام مجدد 
من برای دانلود همین فایل از کد زیر استفاده کردم 
<?php
$extension = explode('.', $model->rezomeh);
$suffix  = end($extension);
$path = Yii::getPathOfAlias('webroot').'/'.$model->rezomeh;
if(!empty($path))
    if(!file_exists($path)){
        echo 'فایل وجود ندارد';
        Yii::app()->end();
    }
    else {
      
        if ($suffix == 'doc' || $suffix == 'docx')
            header("Content-type:application/msword");
        if($suffix == 'pdf' )
            header("Content-type:application/pdf"); //for pdf file
        //header('Content-Type:text/plain; charset=ISO-8859-15');
        //if you want to read text file using text/plain header
        header('Content-Disposition: attachment; filename="'.basename($path).'"');
        header('Content-Length: ' . filesize($path));
        Yii::app()->getRequest()->sendFile( 'tet' , file_get_contents( $path ) );
  
        Yii::app()->end();
        
    }
?>
ولجی وقتی کد اجرا میشه با خطا مواجه میشم 
File not found
Firefox can't find the file at http://localhost/panel/manager/cooperation/download.
    Check the file name for capitalization or other typing errors.
    Check to see if the file was moved, renamed or deleted.
 
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.