图片没有上传到我们给的文件夹中

你的爸爸

Controller / imagesController.php

<?php 
class ImagesController extends AppController
{
public $helpers = array('Html', 'Form', 'Session');
    public $components = array('Session');


    var $uses=array('Images');

    public function index(){

    //  $this->set('posts', $this->carrier->find('all'));
        if($this->request->is('post')){
             Configure::read();
             pr($this->data); 
            $this->Images->create();
            $filename = null;


if (
    !empty($this->request->data['Images']['fname']['tmp_name'])
    && is_uploaded_file($this->request->data['Images']['fname']['tmp_name'])
) {
    // Strip path information
    $filename = basename($this->request->data['Images']['fname']['name']); 
    pr($filename);
    move_uploaded_file( $this->data['Images']['fname']['name'],WWW_ROOT . DS . 'UserImages' . DS . $filename  );

//$this->data['Images']['fname'] = $filename;
}

pr($filename);
// Set the file-name only to save in the database
//pf_($fiename);
$this->request->data['Images']['fname'] = $filename;
$uid = $this->Auth->user('id');
$this->request->data['Images']['uid'] = $uid;
//pf_($this->request->data);
if ($this->Images->save($this->request->data)) {
  pr($this->request->data);
   // ...
     /*if ($this->Carrier->save($this->request->data)) {
                 if ($this->Carrier->save($this->data)) {
                 */
                $this->Session->setFlash(__('Your Details has been saved.'));
                 return $this->redirect(array('controller'=>'images','action' => 'index'));
            } else {
                $this->Session->setFlash(__('Unable to add your Details'));
            }
            }
        }



public function isAuthorized($user) {
    // All registered users can add posts
    if ($this->action === 'index') {
        return true;
    }




    return parent::isAuthorized($user);
}
}
?>

查看/图片/index.ctp

<?php echo $this->Form->create('Images', array('enctype' => 'multipart/form-data'));?>
<?php echo $this->Form->input('Images.fname', array('between'=>'<br />','type'=>'file'));?>

<?php echo $this->Form->end('Apply');?> 

这里的文件上传代码显示可疑和文件名在db中inserterd,但原始图像未上传到UserImages文件夹中..对此进行了检查,但我没有找到解决方法,请帮助我

Noslone

$this->data['Images']['fname']['name']仅包含文件名。$this->data['Images']['fname']['tmp_name']包含文件数据,应与move_uploaded_file();一起使用

所以你应该改变

move_uploaded_file($this->data['Images']['fname']['name'], WWW_ROOT.DS.'UserImages'.DS.$filename)

move_uploaded_file($this->data['Images']['fname']['tmp_name'], WWW_ROOT.DS.'UserImages'.DS.$filename)

您也可以检查一下 move_uploaded_file()

if(move_uploaded_file($this->data['Images']['fname']['tmp_name'], WWW_ROOT.DS.'UserImages'.DS.$filename)) {
    //continue
} else {
    //show error
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

图片上传到我的文件夹中,没有扩展名,带有节点 js 和 multer

我从 Postman 上传到我的 Laravel API 的图像没有保存在文件夹中

Django 图像没有上传到我的“media/user_profile_picture”文件夹中

为什么我的图片没有上传到我的 html 文件

将图片上传到文件夹

图片无法上传到文件夹

上传图片并保存到我的php文件夹中

我们如何检查 HDFS 文件夹中是否有可用的 avro 文件?

Rails:允许用户将图像上传到Dropbox链接文件夹或Amazon S3上“我们的”存储的最佳方法

使用PHP将图片上传到文件夹

将多张图片上传到所需的文件夹

无法将图片上传到文件夹

为什么我的项目中的客户端文件夹没有上传到gitHub上?

我编辑了gitignore,以允许上传图片存储文件夹,但是当我推送内容时,没有任何更新

图片未上传到Django中的媒体文件夹

我们如何简单地在reactjs中上传文件夹?

我的用户无法将文件上传到www-data拥有的文件夹中

在 smarty version3 中,我在文件夹结构中看到我们有 2 个插件目录,应该用于创建自定义插件功能?

我们可以在单个 Function App 中拥有两个单独的 bin 文件夹吗?

Laravel 4,Ubuntu,Apache,我将文件上传到一个文件夹中

Pouchdb在哪里将附件保存到我们的本地PC?我们可以检查哪个文件夹?

我们如何在swift中检查资产文件夹中是否存在文件?

将图片从图库保存到我的文件夹外部SD中?

文件未上传到文件夹中

使用 PHP 将本地文件夹中的所有文件上传到 SFTP

我们该如何通过掌舵遍历位于“ templates”文件夹中的文件?

有没有一种方法可以将文件夹上传到Azure TFVC存储库中?我只看到上传文件的选项

我们如何一次对所有子文件夹执行终端命令

我们如何使用MediaStore类(ANDROID)获取所有包含图像的文件夹?