FAQ
This is my php.It insert data into the database but it dont upload to the
directory..thnx in advanced

class NewslettersController extends AppController
{

var $name='Newsletters';
var $uses=array("Newsletter");
var $helpers = array('Form', 'Session', 'Html');

//allowed upload files
var $validateFile = array(
'size' => 204800,
'type' => 'txt','pdf','doc','docx');

/**
* Public Vars
*/
function index()
{
}

function upload()
{
$path = empty($path) ? WWW_ROOT.'/files/' : $path;
$site_url1="www.realty1-test.co.za";
$site_url2="/app/webroot/files";
$linkpath=$site_url1.$site_url2;
$new_path=str_replace($path,$site_url2,$linkpath);
$path='Libraries/Documents/Adobe';
$no = 1;
$fileName=$_FILES['file']['file_name'];

//print_r($path);
//echo $path;
while (file_exists("$linkpath/".$fileName))
{
$no++;
$newFileName = substr_replace($fileName, "_$no.", strrpos($fileName,
"."), 1);

}
//Get file type

$typeArr = explode('/', $_FILES['file']['type']);

if (($this->validateFile['size'] && $_FILES['file']['size'] >
$this->validateFile['size']) || $_FILES['file']['error'] ==
UPLOAD_ERR_INI_SIZE)
{
$error = 'File is too large to upload';
}
if ($this->validateFile['type'] && (strpos($this->validateFile['type'],
strtolower($typeArr[1]=0)==false)))
{

$error = 'Invalid file type';
}
else
{

if ($_FILES['file']['error'] == UPLOAD_ERR_OK)
{

if (is_uploaded_file($_FILES['file']['tmp_file']))
{
//if (!move_uploaded_file($fileData['tmp_name'], $linkpath.$fileName))
if (move_uploaded_file($fileName, $linkpath.$fileName))
{
$error = 'file uploaded';

}

}
else
{
$error = 'could not move the file';
}
print_r($error);
// print_r($linkpath);

}
}
$linkpath=$this->data['Newsletter']['url'];
if (empty($this->data))
{
$this->Newsletter->create();
}
else
{
$err = false;
if (!empty($this->data['Newsletter']['url']))
{
$fileName =
$this->generateUniqueFilename($this->data['Newsletter']['url']);
$query = $this->Newsletter->query("INSERT INTO newsletters
(news_name, url, status)
VALUES('{$fileName}', '{$new_path}', 'Active')");
$error =
$this->handleFileUpload($this->data['Newsletter']['url'], $fileName);

}
else
{
print_r($this->data);
}
if (!$error)
{
$this->data['Newsletter']['url'] = $fileName;
if ($this->Newsletter->save($this->data))
{
$this->Session->setFlash(__('The Attachment has been
saved',true));
//$this->redirect(array('admins'=>'index'));
}
else
{
$err = true;
}
}
else
{
$this->Newsletter->set($this->data);
}


if ($error || $err)
{
$this->set('error', $error);
$this->set('data', $this->data);
$this->validateErrors($this->Newsletter);
$this->render();
}
}

}
function download()
{


//echo $urlquery;
//$fileName='';
$site_url1="www.realty1-test.co.za";
$site_url2="/app/webroot/files/";
$linkpath=$site_url1.$site_url2.$fileName;
$path = empty ($path) ? WWW_ROOT.'/files/' : $path;
$count=1;
$new_path=str_replace($path,$site_url2,$linkpath);
//$path='Libraries/Documents/Adobe';
$urlquery = $this->Newsletter->query("SELECT url FROM newsletters WHERE
status='Active'");
$hyperlink="";
foreach($urlquery as $URL)
{
$hyperlink=$URL['Newsletter']['url'];
echo "<a href=\"".$hyperlink."\">Newsletter</a> <br/>";


}


}
}
And this is my html
<td align="center">
<form name="register" method="post" action="/newsletters/upload"
onsubmit="return validateForm();">
<table>
<tr>
<td>News Letter</td>
<td> </td>
<td><input type="file" name="file" id="file"/></td>

</tr>
<tr>
<td></td>
</tr>
<tr>
<td></td>
<td><td><input type="submit" value="Upload" /></td>
</tr>
</table>
</form>
</td>

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcake-php @
categoriesphp
postedJun 14, '12 at 1:28p
activeJun 14, '12 at 1:28p
posts1
users1
websitecakephp.org
irc#cakephp

1 user in discussion

Ditshwanelo: 1 post

People

Translate

site design / logo © 2022 Grokbase