FatalThrowableError call to undefined function FirstProject\Http\Controllers\move() - laravel-5

i m learning a tutorial on fileupload in laravel.
my file is not being uploaded.
there seems to be problem at this code.
//move uploaded file
$destinationPath = 'uploads';
$file = move($destinationPath,$file->getClientOriginalName());
and where exactly i need to create a destination path
These are my full codes
uploadfile.php
<body>
<?php
echo Form::open(array('url' => '/uploadfile','files' => 'true'));
echo "Select the file to upload!";
echo Form::file('image');
echo Form::submit('Upload File');
echo Form::close();
?>
</body>
FileUploadController.php
<?php
namespace FirstProject\Http\Controllers;
use Illuminate\Http\Request;
class FileUploadController extends Controller
{
public function index(){
return view('uploadfile');
}
public function showUploadFile(Request $req){
$file = $req->file('image');
//display the fullname
echo "File Name: " .$file->getClientOriginalName();
echo "<br>";
//display file extension
echo "File Extension: " .$file->getClientOriginalExtension();
echo "<br>";
//display file realpath
echo "File Real Path: " .$file->getRealPath();
echo "<br>";
//display file size
echo "File Size: " .$file->getSize();
echo "<br>";
//display file mime type
echo "File Mime Type: " .$file->getMimeType();
//move uploaded file
$destinationPath = 'uploads';
$file = move($destinationPath,$file->getClientOriginalName());
}
}
?>
web.php
Route::get('/uploadfile','FileUploadController#index');
Route::post('/uploadfile','FileUploadController#showUploadFile');

Related

Fail to connect Email class in codeigniter with PHP

I am sending my code but it gives following error to send email.
A PHP Error was encountered Severity: Warning Message: mail()
[function.mail]: Failed to connect to mailserver at "localhost" port
25, verify your "SMTP" and "smtp_port" setting in php.ini or use
ini_set() Filename: libraries/Email.php Line Number: 1554
Code is as following.
email.php file is a following.
<?php
class Email extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->helper('form');
}
public function index()
{
$this->load->view('contact');
}
public function send()
{
$this->load->library('email');
$name=$this->input->post('name');
$form=$this->input->post('form');
$subject=$this->input->post('sub');
$msg=$this->input->post('message');
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl:/gamil.smtp.com';
$config['smtp_port'] = 25;
$config['smtp_user'] ='rameshjadav133#gmail.com';
$config['smtp_pass'] ='jadav4545';
$this->load->library('email',$config);
$this->email->from($form,$name);
$this->email->to('rameshjadav133#gmail.com');
$this->email->subject($subject);
$this->email->message($msg);
if($this->email->send())
{
$data = array('message' =>'Email send success fulll....' );
}
else
{
$data = array('message' => 'Email not send' );
}
$this->load->view('contact',$data);
}
}
?>
contact.php file is as following.
<!DOCTYPE html>
<html>
<head>
<title>Contact form</title>
</head>
<body>
<?php
if(isset($message))
{
echo $message;
}
echo "<h1>Contact form </h1>";
echo form_open("email/send");
echo form_label("Name : ");
echo form_input("name");
echo "<br>";
echo form_label("From : ");
echo form_input("from");
echo "<br>";
echo form_label("Subject : ");
echo form_input("sub");
echo "<br>";
echo form_label("Message");
$data = array('name' => 'message','rows'=>5,'cols'=>32 );
echo form_textarea($data);
echo "<br>";
echo form_submit('submit','send Email');
echo form_close();
?>
</body>
</html>

Uploading files with CodeIgniter

I am using CodeIgniter to download a file created by using the following code:
header('Content-type: text/csv');
header('Content-disposition: attachment;filename=Pricemaster.csv');
echo "Category,Supplier,Org Name,Org Modelno,Capacity,Our Modelno,China,OEM + Freight,Cost Price,USD %,USD price,GBP price,INR %,INR Conversion rate,INR price" . PHP_EOL;
foreach ($data as $val) {
$imp = implode(',', $val);
echo $imp . PHP_EOL;
}
I want to save this file to my upload folder. How can I do this?
You can write files to the server by using the File Helper
Firstly load the file helper:
$this->load->helper('file');
Then try this:
$file_path = './uploads/file.php'
$output = "Category,Supplier,Org Name,Org Modelno,Capacity,Our Modelno,China,OEM + Freight,Cost Price,USD %,USD price,GBP price,INR %,INR Conversion rate,INR price" . PHP_EOL;
foreach ($data as $val) {
$imp = implode(',', $val);
$output .= $imp . PHP_EOL;
}
if ( ! write_file($file_path, $output)) {
echo 'Unable to write the file';
} else {
echo 'File written!';
}
You'll want to change the file name / path accordingly. The data will obviously be your CSV output.
If the file writes successfully you can use this path to attach to your email.

How to upload a different copy of a file?

I need help on how to get this code to take image files, rename them and upload separate copies. I want the original copies to be left exactly as they are.
<?php
$fileName = $_FILES["uploaded_file"]["name"];
$fileTmpLoc = $_FILES["uploaded_file"]["tmp_name"];
$fileType = $_FILES["uploaded_file"]["type"];
$fileSize = $_FILES["uploaded_file"]["size"];
$fileErrorMsg = $_FILES["uploaded_file"]["error"];
$fileName = preg_replace('#[^a-z.0-9]#i', '', $fileName);
$kaboom = explode(".", $fileName);
$fileExt = end($kaboom);
$fileName = rand(1, 10).".".$fileExt;
if (!$fileTmpLoc) {
echo "ERROR: Please browse for a file before clicking the upload button.";
exit();
} else if($fileSize > 5242880) {
echo "ERROR: Your file was larger than 5 Megabytes in size.";
unlink($fileTmpLoc);
exit();
} else if (!preg_match("/.(gif|jpg|png)$/i", $fileName) ) {
echo "ERROR: Your image was not .gif, .jpg, or .png.";
unlink($fileTmpLoc);
exit();
} else if ($fileErrorMsg == 1) {
echo "ERROR: An error occured while processing the file. Try again.";
exit();
}
$moveResult = move_uploaded_file($fileTmpLoc, "uploads/$fileName");
if ($moveResult != true) {
echo "ERROR: File not uploaded. Try again.";
exit();
}
echo "The file named <strong>$fileName</strong> uploaded successfuly.<br /><br />";
echo "It is <strong>$fileSize</strong> bytes in size.<br /><br />";
echo "It is an <strong>$fileType</strong> type of file.<br /><br />";
echo "The file extension is <strong>$fileExt</strong><br /><br />";
echo "The Error Message output for this upload is: $fileErrorMsg";
?>
Can anyone help?

Listing files,subfolders and their files in a file in codeigniter

my Uploads folder structure in codeigniter is like
Uploads
-File1.txt
-File2.txt
-Subfolder 1
-- File1.txt
--File2.txt
-Subfilder2
--File1.txt
I want to display each file name and if that file is in subfilder it should display as Subfilder/File.txt
Thats what my code looks like
" <?php
foreach ($direcotry as $key => $value ) {
if(!is_numeric($key)){
echo $key . '/' ;
foreach ($key as $subKey => $value) {
echo $value . '<br>';
}
}
else{
echo $value . '</br>';
}
}
?>"
![enter image description here][1]
and it gives an error as invalid argument to foreach
CodeIgniter contains directory helper which provides this for you
$this->load->helper('directory');
$map = directory_map('path/to/uploads');
print_r($map)

Magento 1.6.1: How To Get Tracking Number From Order Object in PHP?

How can I find the tracking number associated with each order? I have created a script to output the data. I have tried so many variations, yet they all return blank/null.
Currently, it outputs
103236290 United States Postal Service - First-Class Mail Parcel Mar 23, 2013 10:12:59 PM
Note that the output is tab delimited, so there are two tabs between order id and shipment method.
<?php
//External script - Load magento framework
require_once($_SERVER['DOCUMENT_ROOT'] . "/store/app/Mage.php");
Mage::app('default');
$myOrder=Mage::getModel('sales/order');
$ship = Mage::getModel('sales/order_shipment');
$orders=Mage::getModel('sales/mysql4_order_collection');
$trackings=Mage::getResourceModel('sales/order_shipment_track_collection')->addAttributeToSelect('*')->addAttributeToFilter('parent_id',$ship->getId());
$trackings->getSelect()->order('entity_id desc')->limit(1);
$trackData = $trackings->getData();
$trackID = $trackData[0]['entity_id'];
$from = "2013-03-24 00:00:00"; // orders from date
$to= "2013-06-20 00:00:00"; // orders to date
//Optional filters you might want to use - more available operations in method _getConditionSql in Varien_Data_Collection_Db.
$orders->addFieldToFilter('total_paid',Array('gt'=>0)); //Amount paid larger than 0
$orders->addFieldToFilter('status',Array('eq'=>"Complete")); //Status is: "complete", "processing" "canceled" etc.
$orders->addAttributeToFilter('created_at', array(
'from' => $from,
'to' => $to,
));
$allIds=$orders->getAllIds();
foreach($allIds as $thisId) {
$myOrder->reset()->load($thisId);
echo "<pre>";
//print_r($myOrder);
//Fields to print
echo $myOrder->getRealOrderId() . " ";
echo $trackID . " ";
echo $myOrder->getShippingDescription() . " ";
echo $myOrder->getCreatedAtDate() . " ";
echo "\r\n";
echo "</pre>";
}
?>
Here is the working script. We figured it out :-)
<?php
//External script - Load magento framework
require_once($_SERVER['DOCUMENT_ROOT'] . "/store/app/Mage.php");
Mage::app('default');
$myOrder=Mage::getModel('sales/order');
$ship = Mage::getModel('sales/order_shipment');
$orders=Mage::getModel('sales/mysql4_order_collection');
$trackings=Mage::getResourceModel('sales/order_shipment_track_collection')->addAttributeToSelect('*')->addAttributeToFilter('parent_id',$ship->getId());
$trackings->getSelect()->order('entity_id desc')->limit(1);
$carrierInstances = Mage::getSingleton('shipping/config')->getAllCarriers();
$carriers['custom'] = Mage::helper('sales')->__('Custom Value');
foreach ($carrierInstances as $code => $carrier) {
if ($carrier->isTrackingAvailable()) {
$carriers[$code] = $carrier->getConfigData('title');
}
}
$from = "2013-03-24 00:00:00"; // orders from date
$to= "2013-06-21 00:00:00"; // orders to date
//Optional filters you might want to use - more available operations in method _getConditionSql in Varien_Data_Collection_Db.
$orders->addFieldToFilter('total_paid',Array('gt'=>0)); //Amount paid larger than 0
$orders->addFieldToFilter('status',Array('eq'=>"Complete")); //Status is: "complete", "processing" "canceled" etc.
$orders->addAttributeToFilter('created_at', array(
'from' => $from,
'to' => $to,
));
$allIds=$orders->getAllIds();
foreach($allIds as $thisId) {
$myOrder->reset()->load($thisId);
echo "<pre>";
//print_r($myOrder);
//Some random fields
echo $myOrder->getRealOrderId() . " ";
$trackings = Mage::getResourceModel('sales/order_shipment_track_collection')
->setOrderFilter($myOrder)
->getData();
foreach ($trackings as $tracking) {
echo $tracking['track_number'] . " ";
}
echo $carriers[$tracking['carrier_code']] . " ";
echo $myOrder->getCreatedAtDate() . " ";
// echo "'" . $myOrder->getStatus() . "',";
// echo "'" . $myOrder->getBillingAddress()->getLastname() . "',";
// echo "'" . $myOrder->getTotal_paid() . "',";
// echo "'" . $myOrder->getShippingAddress()->getTelephone() . "',";
// echo "'" . $myOrder->getPayment()->getCc_type() . "',"; // bad code
echo "\r\n";
echo "</pre>";
}
?>

Resources