2

我在magento的自定义模块中上传图像时遇到问题..

我为此目的使用了核心php ccoding,但magento没有上传图像..

我使用相同的代码在本地 xampp 中上传文件。但该代码在我的服务器上不起作用..

我也使用此代码,但它也不起作用....

$path = Mage::getBaseDir().DS.'customer_documents'.DS; //desitnation directory
  $fname = $_FILES['docname']['name']; //file name
  $uploader = new Varien_File_Uploader('docname'); //load class
  $uploader->setAllowedExtensions(array('doc','pdf','txt','docx')); //Allowed extension for file
  $uploader->setAllowCreateFolders(true); //for creating the directory if not exists
  $uploader->setAllowRenameFiles(false); //if true, uploaded file's name will be changed, if file with the same name already exists directory.
  $uploader->setFilesDispersion(false);
  $uploader->save($path,$fname); //save the file on the specified path
4

1 回答 1

1

我在我的代码中添加了这一行并且它正在工作..

<?php require_once ("lib/Varien/File/Uploader.php");?>

在此之后编写此代码

<?php
$path = Mage::getBaseDir().DS.'customer_documents'.DS; //desitnation directory
  $fname = $_FILES['docname']['name']; //file name
  $uploader = new Varien_File_Uploader('docname'); //load class
  $uploader->setAllowedExtensions(array('doc','pdf','txt','docx')); //Allowed extension for file
  $uploader->setAllowCreateFolders(true); //for creating the directory if not exists
  $uploader->setAllowRenameFiles(false); //if true, uploaded file's name will be changed, if file with the same name already exists directory.
  $uploader->setFilesDispersion(false);
  $uploader->save($path,$fname); //save the file on the specified path
?>
于 2012-09-27T06:03:12.853 回答