kickthemooon's avatar

Wamp64, PHP7, Laravel 5.2, tmp folder doesn't store files

So im using wamp64 with php7 im trying to upload images. my form looks likes this:

<form  method="POST" action="/dashboard/nalaz/dodaj/{{ $patients->id}}" enctype="multipart/form-data">
    <input type="file" name="images[]">
</form>

this is my php.ini file uploads configuration

file_uploads = On
upload_tmp_dir ="C:/wamp64/tmp"
upload_max_filesize = 3M
max_file_uploads = 5

Now i do this in my laravel controller

$temp = tmpfile();
$images = $request->file('reportimages');
dd($images);

dd() gives me the array of uploaded files

array:1 [▼
  0 => UploadedFile {#363 ▼
    -test: false
    -originalName: "11082663_10205108991016758_689124932158641809_n.jpg"
    -mimeType: "image/jpeg"
    -size: 42149
    -error: 0
    path: "C:\wamp64\tmp"
    filename: "php95FE.tmp"
    basename: "php95FE.tmp"
    pathname: "C:\wamp64\tmp\php95FE.tmp"
    extension: "tmp"
    realPath: "C:\wamp64\tmp\php95FE.tmp"
    aTime: 2016-05-12 10:21:16
    mTime: 2016-05-12 10:21:16
    cTime: 2016-05-12 10:21:16
    inode: 0
    size: 42149
    perms: 0100666
    owner: 0
    group: 0
    type: "file"
    writable: true
    readable: true
    executable: false
    file: true
    dir: false
    link: false
    linkTarget: "C:\wamp64\tmp\php95FE.tmp"
  }
]

but NOTHING gets written to "C:/wamp64/tmp" so it cannot actually save the immage because there is no image in the tmp folder I am on windows and I granted all permissions for all users for the tmp folder.

0 likes
9 replies
christopher's avatar

Maybe because there is no write access for C:/wamp64/tmp?

kickthemooon's avatar

@christopher "image in the tmp folder I am on windows and I granted all permissions for all users for the tmp folder."

SaeedPrez's avatar

@kickthemooon just for testing, create an empty folder, for example c:\temp and try this..

// move the file
$request->file('whatever')->move('C:\temp');

// move the file and rename it
$request->file('whatever')->move('C:\temp', 'filename.jpg');

Keep in mind that PHP deletes uploaded files when the request ends.

kickthemooon's avatar

@Prez

Fatal error: Call to a member function move() on array

Its a multiple file upload...

SaeedPrez's avatar

@kickthemooon why am I so damn soft?

foreach($request->file('whatever') as $file) {
    $file->move('path-to-folder', 'filename');
}

Also don't forget multiple attribute on the input tag so you can select multiple files..

<input type="file" name="images[]" multiple>
kickthemooon's avatar

@Prez Ok I am using spatie/laravel-medialibrary and this is my controller

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

        foreach($images as $image){
            $image = $image->move('C:\tmp');
            $report->addMediaFromRequest($image)->toCollection('medical-reports');
        }

Now since i am moving the file to c:\tmp it appears there, so it is moved successfully but I still get this error

FileCannotBeAdded in FileCannotBeAdded.php line 49:
The current request does not have a file in a key named `C:\tmp\phpE5B.tmp`

here is the the media-library method

public static function createFromRequest(Model $subject, string $key)
    {
        if (!request()->hasFile($key)) {
            throw FileCannotBeAdded::requestDoesNotHaveFile($key);
        }

        return static::create($subject, request()->file($key));
    }

Please or to participate in this conversation.