
22.05.2010, 00:15
|
|
Познающий
Регистрация: 25.12.2008
Сообщений: 34
С нами:
9145978
Репутация:
6
|
|
Добрый день.
есть форма
Код HTML:
<form method="post" enctype="multipart/form-data" accept-charset="utf-8" action="upload.php">
<fieldset>
<legend>Настройки импорта:</legend>
<table>
<tr>
<td class="label">
<label for="type">Тип прайса: </label>
</td>
<td class="field">
<select name="type">
<option value="1">Минотавр</option>
<option value="2">Форвард</option>
</select>
</td>
</tr>
<tr>
<td class="label">
<label for="multiplier">Множитель цены (курс €, только для "Минотавр"): </label>
</td>
<td class="field">
<input type="text" name="multiplier" value="31" />
</td>
</tr>
<tr>
<td class="label">
<label for="prefix">Префикс для заголовка: </label>
</td>
<td class="field">
<input type="text" name="prefix" value="Кузовные запчасти и оптика/" />
</td>
</tr>
</table>
</fieldset>
<fieldset>
<legend>Загрузка файла:</legend>
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $upload->getFilesizeLimit(0); ?>" />
<table>
<tr>
<td class="label">
<label for="userfile">XLS-файл: </label>
</td>
<td class="field">
<input type="file" name="userfile" />
</td>
</tr>
<tr>
<td colspan="2" class="submit">
<input type="submit" value="Загрузить" />
</td>
</tr>
</table>
</fieldset>
</form>
Как видно из кода, требуется передать не сервер файлик, в рабочем виде можно увидеть здесь
Пример того что грузим здесь
При загрузке выбрать тип - форвард
При попытке загрузить получаю - Method Not Allowed
The requested method POST is not allowed for the URL /admin/upload.php.
Сам аплоад.пхп
PHP код:
<?php
define( 'FROM_INDEX', true );
define( 'ROOTPATH', dirname(__FILE__) . '/' );
require_once ROOTPATH . '/includes/config.inc.php';
require_once ROOTPATH . '/includes/functions.inc.php';
require_once ROOTPATH . 'classes/upload_wrapper.class.php';
$upload = new UploadWrapper();
require_once ROOTPATH . 'classes/indata_handler.class.php';
$indata = new InDataHandler();
require_once ROOTPATH . 'classes/excel_reader.class.php';
$file_type = $indata->getVar( 'type', 'int', 'gp' );
$price_multiplier = $indata->getVar( 'multiplier', 'float', 'gp' );
$header_prefix = $indata->getVar( 'prefix', 'html', 'gp' );
$result = $upload->doUploadFile(
$_FILES['userfile'],
$config['temp_dir'],
0,
'price' . $file_type . '.xls'
);
if ( $result == false )
{
echo '<h1>РћС?РёР±РєР° загрузки:</h1>', $upload->getUploadError();
}
else
{
$xls_data = new Spreadsheet_Excel_Reader(
$config['temp_dir'] . 'price' . $file_type . '.xls',
true
);
switch ( $file_type )
{
case 1:
require_once ROOTPATH . 'includes/price1.inc.php';
break;
case 2:
require_once ROOTPATH . 'includes/price2.inc.php';
break;
}
}
?>
И класс upload_wrapper
PHP код:
<?php
if ( !defined('FROM_INDEX') )
{
die('Hacking attempt!');
}
class UploadWrapper
{
private $upload_errors = array(
UPLOAD_ERR_INI_SIZE => 'The uploaded file exceeds the upload_max_filesize directive in php.ini.',
UPLOAD_ERR_FORM_SIZE => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.',
UPLOAD_ERR_PARTIAL => 'The uploaded file was only partially uploaded.',
UPLOAD_ERR_NO_FILE => 'No file was uploaded.',
UPLOAD_ERR_NO_TMP_DIR => 'Missing a temporary folder.',
UPLOAD_ERR_CANT_WRITE => 'Failed to write file to disk.',
UPLOAD_ERR_EXTENSION => 'File upload stopped by extension.',
);
private $max_filesize = 0;
private $max_postsize = 0;
private $upload_error = '';
public function __construct()
{
$this->max_filesize =
$this->convert_phpini_bytes( ini_get('upload_max_filesize') );
$this->max_postsize =
$this->convert_phpini_bytes( ini_get('post_max_size') );
}
public function convert_phpini_bytes( $value )
{
if ( ! is_numeric( $value ) )
{
$mul = strtolower( substr( $value, -1 ) );
$mul = ( $mul === 'm' ? 1048576 :
( $mul === 'k' ? 1024 :
( $mul === 'g' ? 1073741824 : 1 )
) );
$value *= $mul;
}
return $value;
}
public function getMaxUploadFilesize()
{
return ( $this->max_postsize < $this->max_filesize ) ?
$this->max_postsize : $this->max_filesize;
}
public function getFilesizeLimit( $limit=0 )
{
$php_max_filesize = $this->getMaxUploadFilesize();
return ( $limit && ( $php_max_filesize > $limit ) ) ?
$limit : $php_max_filesize;
}
public function doUploadFile( $file, $dest, $sizelimit=0,
$name='', $allowd_mime=null )
{
$this->upload_error = 'Unknown error uploading file.';
if ( isset( $file['tmp_name'] ) &&
$file['size'] &&
( $file['error'] === UPLOAD_ERR_OK ) )
{
if ( $sizelimit && ( $file['size'] > $sizelimit ) )
{
$this->upload_error = $this->upload_errors(UPLOAD_ERR_FORM_SIZE);
}
elseif ( $allowd_mime && is_array($allowd_mime) &&
( ! in_array( $file['type'], $allowd_mime ) ) )
{
$this->upload_error = 'Incorrect file type.';
}
else
{
$filename = ( $name ? $dest . $name : $dest . $file['name'] );
if ( move_uploaded_file( $file['tmp_name'], $filename ) )
{
chmod( $filename, 0777 );
$this->upload_error = '';
}
else
{
$this->upload_error = 'Can\'t move file to uploading folder.';
}
}
}
elseif ( isset( $this->upload_errors[ $file['error'] ] ) )
{
$this->upload_error = $this->upload_errors[ $file['error'] ];
}
return ( $this->upload_error ? false : true );
}
public function getUploadError()
{
return $this->upload_error;
}
}
?>
Подскажите в чем накосячил?пхп.ини привести не могу, тк действо происходит на хостинге. на всякий случай приведу еще и то, что .htaccess написал
AddDefaultCharset UTF-8
<FilesMatch "\.(php|htm|html)$">
ForceType 'text/html; charset=UTF-8'
</FilesMatch>
php_value max_execution_time 300
php_value post_max_size 10M
php_value upload_max_filesize 10M
<Files .htpasswd>
deny from all
</Files>
RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html .phtml
|
|
|