bool mkdir ( string $pathname [, int $mode = 0777 [, bool $recursive = false [, resource $context ]]] )
$pathname
should be the server path to the file and not a url
Try
$path = Mage::getBaseDir('media') . DS;
You should try using Varien_File_Uploader
include_once Mage::getBaseDir() . '/lib/Varien/File/Uploader.php'; /* Starting upload */ $uploader = new Varien_File_Uploader('filename'); // Any extention would work $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png')); $uploader->setAllowRenameFiles(false); // Set the file upload mode // false -> get the file directly in the specified folder // true -> get the file in the product like folders // (file.jpg will go in something like /media/f/i/file.jpg) $uploader->setFilesDispersion(false); // We set media as the upload dir $path = Mage::getBaseDir('media') . DS; $uploader->save($path, $_FILES['filename']['name']);
参考:http://magento.stackexchange.com/a/40744
如果想要裁图的话,可以参考下面代码:
include_once Mage::getBaseDir() . '/lib/Varien/File/Uploader.php'; $file = new Varien_Io_File(); $imageDir = Mage::getBaseDir('media') . DS . 'mbimages'; $thumbimageyDir = Mage::getBaseDir('media').DS.'mbimages'.DS.'thumbs'; if(!is_dir($imageDir)) $imageDirResult = $file->mkdir($imageDir, 0777); if(!is_dir($thumbimageyDir)) $thumbimageDirResult = $file->mkdir($thumbimageyDir, 0777); //echo '<pre>'; print_r($_FILES); echo '==>'.$filename; echo '</pre>'; die; if(isset($_FILES[$filename]['name']) && $_FILES[$filename]['name'] != '') { //echo '==>'.$_FILES[$filename]['name']; try { /* Starting upload */ $uploader = new Varien_File_Uploader($filename); // Any extention would work $uploader->setAllowedExtensions(array('jpg','jpeg','gif','png')); $uploader->setAllowRenameFiles(true); // Set the file upload mode // false -> get the file directly in the specified folder // true -> get the file in the product like folders // (file.jpg will go in something like /media/f/i/file.jpg) $uploader->setFilesDispersion(true); // We set media as the upload dir //$path = Mage::getBaseDir('media') . DS ; $path = $imageDir . DS ; $result = $uploader->save($path, $_FILES[$filename]['name']); $file = str_replace(DS, '/', $result['file']); ############################################################################### // actual path of image $imageUrl = Mage::getBaseDir('media').DS."mbimages".$file; // path of the resized image to be saved // here, the resized image is saved in media/resized folder $imageResized = Mage::getBaseDir('media').DS."mbimages".DS."thumbs".DS."mbimages".$file; // resize image only if the image file exists and the resized image file doesn't exist // the image is resized proportionally with the width/height 135px if (!file_exists($imageResized)&&file_exists($imageUrl)) : $imageObj = new Varien_Image($imageUrl); $imageObj->constrainOnly(TRUE); $imageObj->keepAspectRatio(FALSE); $imageObj->keepFrame(FALSE); $imageObj->quality(100); $imageObj->resize(80, 50); $imageObj->save($imageResized); endif; $data[$filename] = 'mbimages'.$file; } catch (Exception $e) { $data[$filename] = 'mbimages'.'/'.$_FILES[$filename]['name']; } }
更多图片处理方法请参考:magento图片处理 Customize Magento’s Image Resize Functionality
原文/转自:Magento : 调用文件上传 upload file frontend
相关推荐
NULL 博文链接:https://justcoding.iteye.com/blog/2100394
MagentoBeginner's Guide.pdf [Packt]出品,最早的Magento精品书之一,原书地址:http://www.amazon.com/Magento-Beginners-Guide-William-Rice/dp/1847195946
上载带有扩展名的Dropday/OrderAutomation目录。 打开终端并导航到Magento根目录。 运行以下命令以启用Dropday扩展: php bin/magento module:enable Dropday_OrderAutomation 运行Magento安装程序升级: ...
magento:magento-ce 2.4.0
Magento:registered:2数据集成借助Datatric Connect扩展程序,可以轻松地将Magento:registered:2商店与Datatrics平台连接起来。安装在开始安装过程之前,我们建议您对webshop文件以及数据库进行备份。 有两种安装...
magento:Magento CE 1.x源代码
Magento No Flash Upload插件,替换原有的Flash上传
fresh-magento:新鲜的magento
docker-magento:Mark Shust的Magento Docker配置
要更新版本,改版本号和运行gulp创建Magento的包文件。 执照 麻省理工学院许可证 (MIT) 版权所有 (c) 2014 Gimmieworld pte ltd。 特此授予任何人免费获得本软件副本和相关文档文件(“软件”)的许可,不受限制...
Apress.The.Definitive.Guide.to.Magento.Dec.2009.pdf Apress于2009重磅推出的Magento上手书籍,原书地址:http://www.apress.com/book/view/9781430272298
magento:megento电子商务网站
ansible-magento要求: -流浪汉-可以指示: 克隆此仓库无所事事在浏览器中导航到magento.dev。MySQL 数据库:magento 用户名:magento 密码:password123 这是基于的工作而进行的一些更改,以简化启动和运行过程...
校园2021-Magento 提交消息应包括: 任务编号: #2 简短的任务名称: Add Websites: 做了什么:`为新域更新了Docker配置 例子: #2 Add Websites: updated Docker configuration for new domain Git Flow DV。...
VueFrontCMS Connect App for Magento 显示你的 :red_heart: -给我们一个 :star: 帮助我们将这个项目发展到最好! VueFront是CMS不可知的SPA和PWA前端,适用于您的老式Blog和电子商务网站。 Magento通过最佳的电子...
马恩托 magento 项目
马真托Magento片段。
$ cd /path/to/magento $ modgit init $ modgit add epicomtech_magento https://github.com/epicomtech/magento.git Antes deComeçar Epicom的API协议 通过电子邮件联系API,电子邮件地址: Conhecendo omó...
deployer-extended-magento:Magento的基于部署程序的部署,具有媒体和数据库同步
流浪者-magento:**已弃用**