mardi 26 avril 2016

How i can make a directory whith ID of user or client on laravel

Well, actually i want make a directoy when i chose some client on the list and he want upload the image with dropzone , so if he dont have a directory then make or if exists save the image on the own directory , well rigth now i upload the images on one directory but i want create one per user , here is my method to store, im really new on this things sorry.

Thanks for your help so much.

public function store(Storage $storage, Request $request)
{
    if ($request->isXmlHttpRequest()) {

        $file = $request->file('file');

        $timestamp = $this->getFormattedTimestamp();
        $savedImgName = $this->getSavedImageName($file, $timestamp);
        $imageUploaded = $this->uploadImage($file, $savedImgName, $storage); * /

        if ($imageUploaded) {
            $data = [
                'original_path' => asset('/uploads/'.$savedImgName)
            ];

            return json_encode($data, JSON_UNESCAPED_SLASHES);
        }

        return "uploading failed";
    }
}


public function uploadImage($file, $imageFullName, $storage)
{
    $filesystem = new Filesystem;

    return $storage->disk('file')->put($imageFullName, $filesystem->get($file));
}

protected function getFormattedTimestamp()
{

    return str_replace([' ', ':'], '-', Carbon::now()->toDateTimeString());

}

protected function getSavedImageName($file, $timestamp)
{

    return $timestamp.'-'.$file->getClientOriginalName();
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire