作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
你好 friend 我想通过 laravel 中的 excel 使用 laravel excel 插件上传学生数据,我想用 excel 文件上传图像(通过本地路径或其他)
请建议我解决这个问题
我创建了一个在我的本地服务器上上传文件但在服务器上不起作用的函数
$excel = Excel::load(Input::file('file'))->get();
foreach($excel as $exc) {
$data = $exc->all();
$data['class_id'] = $id;
$data['school_id'] = $class->school_id;
if ($student = Student::firstOrCreate($data)) {
if (File::exists($exc->image)) {
$destinationPath = 'uploads/schools/' . $class->school_id . '/' . $class->id . '/' . $student->id . '/'; // upload path
if (!file_exists($destinationPath)) {
mkdir($destinationPath, 0755, true);
}
$file = file_get_contents($exc->image);
$fileName = str_slug(Carbon::now()->toDayDateTimeString()) . rand(11111, 99999) . '.jpg'; // renameing image
if(file_put_contents($destinationPath.$fileName,$file)) {
$student->image = $destinationPath . $fileName;
$student->update();
}
}
}
}
最佳答案
$objphpexcel = PHPExcel_IOFactory::load("MyExcelFile.xls");
foreach ($objphpexcel ->getSheetByName("My Sheet1")->getDrawingCollection() as $drawing) {
if ($drawing instanceof PHPExcel_Worksheet_MemoryDrawing) {
ob_start();
call_user_func(
$drawing->getRenderingFunction(),
$drawing->getImageResource()
);
$imageContents = ob_get_contents();
ob_end_clean();
$cellID = $drawing->getCoordinates();
// .... do your save here
}
}
关于php - Laravel 通过 excel 上传图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46488754/
我有以下正则表达式 /[a-zA-Z0-9_-]/ 当字符串只包含从 a 到z 大小写、数字、_ 和 -。 我的代码有什么问题? 能否请您向我提供一个简短的解释和有关如何修复它的代码示例? //var
我是一名优秀的程序员,十分优秀!