I have a file attachment feature in a Laravel package. I want the uploaded file to save in the project using the package and NOT in the package. Currently, the file is uploaded into the package instead of the project.
Controller:
$attachment->spot_buy_item_id = $id;
$attachment->name = $_FILES['uploadedfile']['name'];
$attachment->created_ts = Carbon::now();
$ds = DIRECTORY_SEPARATOR; //1
$storeFolder = '../../../resources/uploads';
if (!empty($_FILES)) {
$tempFile = $_FILES['uploadedfile']['tmp_name']; //3
$extension = pathinfo($_FILES['uploadedfile']['name'], PATHINFO_EXTENSION);
$attachment_hash = md5($tempFile);
$new = $attachment_hash.'.'.$extension;
// complete creating attachment object with newly created attachment_hash
$attachment->hash = $new;
$attachment->save();
$targetPath = dirname( __FILE__ ) . $ds. $storeFolder . $ds; //4
$targetFile = $targetPath. $new; //5
move_uploaded_file($tempFile,$targetFile); //6
chmod($targetFile, 0777);
}
else
{
return "error";
}
Service Provider (I thought publishing the uploads folder might work - nope.)
public function boot()
{
require __DIR__ . '/Http/routes.php';
$this->loadViewsFrom(__DIR__ . '/resources/views', 'ariel');
$this->publishes([
__DIR__ . '/resources/uploads' => public_path('vendor/uploads'),
], 'public');
$this->publishes([
__DIR__ . '/../database/migrations' => database_path('migrations')], 'migrations');
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire