我遇到此错误"无法上传指定的文件。请检查你的路径。"。该文件正在我的本地和我的SQL数据库中上传,但我不知道为什么它没有在我的远程路径上传。
无论如何这就是我想要发生的事情,我想将文件上传到我的数据库和我的远程路径,因为我无法找到其他参考代码,所以我的本地副本并不是必需的。
你可以查看我的代码是否有问题吗?
控制器
function upload_gen048()
{
$data['filedate']=$this->input->post('fiil');
//print_r ($data);
$this->load->model('navi_model');
$query = $this->navi_model->upload_gen048($data);
$this->file_path = realpath(navi_ups.'/gen048');
$config['upload_path'] = $this->file_path;
$config['max_size'] = 0;
$config['allowed_types'] = 'txt';
//$config['overwrite'] = TRUE;
$this->load->library('upload');
$data['upload'] = $this->upload->data();
$this->upload->initialize($config);
$this->upload->set_allowed_types('*');
if ( !$this->upload->do_upload('uploadData'))
{
$data['error'] = $this->upload->display_errors();
$this->ftp->close();
}
else {
//else, set the success message
$this->load->library('ftp');
$config['hostname'] = '000.000.00.102';
$config['username'] = '***ana';
$config['password'] = '***ana123_';
$config['debug'] = TRUE;
$this->ftp->connect($config);
$this->ftp->upload(navi_ups. '/gen048','Y:/FTP/RMT', 'auto', 0775);
$data = array('msg' => "Upload success!");
$this->ftp->close();
}
}
模型
function upload_gen048($data)
{
$x = explode('.',$data['filedate']);
//print_r ($data);
$qString = "";
$qString .= '[dbo].[gen048upload] '; //STORED PROCEDURE
$qString .= "'" .$data['filedate']."'";
//echo $qString;
$query = $this->db->query($qString);
print_r($query->result());
return ($query->num_rows() > 0 ? $query->result() : NULL);
}
存储过程
ALTER PROCEDURE [dbo].[gen048upload]
(
@fileDate VARCHAR(20)
)
AS BEGIN
SET NOCOUNT ON
declare @sql varchar(8000),@sourceTable varchar(500), @dynamic varchar(8000), @tablesuffix varchar(10)
select @tablesuffix=upper(substring(datename(m,convert(datetime,@fileDate)),1,3))+convert(varchar,year(convert(datetime,@fileDate)))
print @tablesuffix
declare @currmonth varchar(10)
select @dynamic=''
create table #logs(
i int identity(1,1),
tableName varchar(50),
status varchar(30)
)
set @sourceTable ='gen_048_'+@tablesuffix
insert into #logs(tableName,status) select @sourceTable,'CREATED'
IF NOT EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'dbo' AND TABLE_NAME = @sourceTable)
BEGIN
set @sql = '
CREATE TABLE '+@sourceTable+'
(
[flag] [int] NULL,
[accname] [varchar](255) NULL,
[accdate] [varchar](25) NULL,
[uname] [varchar](255) NULL,
[accnum] [varchar](255) NULL,
)
'
print @sql
exec (@sql)
-- '+@dynamic+' if @@ERROR<>0 BEGIN update #logs set status='ERROR' where tableName=@sourceTable END
SET NOCOUNT ON;
CREATE TABLE #temp (WHOLEROW VARCHAR(8000))
IF OBJECT_ID('tempdb.dbo.#temp') IS NOT NULL
DROP TABLE #temp
CREATE TABLE #temp1 (WHOLEROW VARCHAR(8000))
BEGIN TRY
BEGIN TRANSACTION
DECLARE @SQL2 NVARCHAR(MAX)
SET @SQL2 = 'BULK INSERT #temp1
FROM ''Y:\FTP\RMT\' + @fileDate + '.txt' + '''
WITH (DATAFILETYPE = ''char'', KEEPNULLS, FIRSTROW=1, MAXERRORS=0, ROWTERMINATOR = ''' + CHAR(0x0A) + ''')'
EXEC sys.sp_executesql @SQL2