CodeIgniter Forums
Still getting error in uploading/downloading file....HELP. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Still getting error in uploading/downloading file....HELP. (/showthread.php?tid=15253)



Still getting error in uploading/downloading file....HELP. - El Forum - 01-29-2009

[eluser]cpp643[/eluser]
Here is my code....it is compulsory to upload same file which is on server.if same file is uploaded then rename the original file on server,and upload new one, but it will show "invalid file error msg".and if suppose that file is uploaded on server and then if i will download that file then it will show corrupted zip file... can any buddy help...???

$folderName = strtoupper($this->postfilename); // uloaded file
$origFileName = strtoupper($this->filename);

$tempFolder = explode("-",$folderName);
$folderIndex = "userfile";
if(count($tempFolder) > 1)
{
$folderName = $tempFolder[1];
$tempVar = $tempFolder[0];

$folderIndex = $folderIndex."_".$tempVar;
}

list($tempFlderNameArr,$extention) = explode(".",$folderName);

$flderNameArr = explode("/",$tempFlderNameArr);

$flderName = $flderNameArr[count($flderNameArr)-1];

$globalPath = "../abc/abcd/".$origFileName."/";
$serverFileName = $globalPath.$origFileName.".zip";


if(file_exists($serverFileName))
{
$newFileName = $globalPath.strtolower($origFileName)."_".date('Y').date('m').date('d')."_".date('H').date("i").date("s").".zip";

if(rename($serverFileName,$newFileName))
{
$config['allowed_types'] = 'zip';
$config['max_size'] = '10240';

$config['upload_path'] = $globalPath;

$this->load->library('upload', $config);

if (!$this->upload->do_upload($folderIndex))
{
rename($newFileName,$serverFileName);
$error = array( 'error' => 'Invalid File',

);

$this->load->view('uploadFile', $error);
}
else
{
$data = array('upload_data' => $this->upload->data($folderIndex));
$dataArr = $data['upload_data'];
$upFileName = $dataArr['file_name'];
$tempFileName = $origFileName.'.zip';

if(strtolower($upFileName) == strtolower($tempFileName))
{
//good ...

}
else
{
rename($newFileName,$serverFileName);
unlink($globalPath.$upFileName);
$error = array('error' => 'Please upload '.$origFileName.".zip",

);
$this->load->view('uploadFile', $error);
}
}
}
else
{
$error = array('error' => 'Error in renaming the server file',

);
$this->load->view('uploadFile', $error);
}
}
else
{
unlink($globalPath.$upFileName);
$error = array( 'error' => 'Main file is not found on server',

);
$this->load->view('uploadFile', $error);
}