I want to upload a video file to a server using POST request. There is not much information available about it in the internet.
I usually do check the data what i have send using this code
$params = $_REQUEST;
return $params;
I check it in POSTMAN. I have table called video_review
id
video_url
movie_id
user_id
date_time
when i choose a video file and click send i want the location of video file to be saved into the video_url field. But in the controller when i run this code return $params; i get nothing.
EDIT
Made some progress
public function actionCreate_video_review()
{
$allowedExts = array("jpg", "jpeg", "gif", "png", "mp3", "mp4", "wma","mkv");
$extension = pathinfo($_FILES['video_url']['name'], PATHINFO_EXTENSION);
if ( ($_FILES["video_url"]["type"] == "video/mp4")|| ($_FILES["video_url"]["type"] == "video/x-matroska")
&& ($_FILES["video_url"]["size"] < 20000)
&& in_array($extension, $allowedExts) )
{
if ($_FILES["video_url"]["error"] > 0)
{
return $_FILES["video_url"]["error"];
}
else
{
if (file_exists("upload/" . $_FILES["video_url"]["name"]))
{
echo $_FILES["video_url"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["video_url"]["tmp_name"],
"upload/" . $_FILES["video_url"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["video_url"]["name"];
return $_FILES["video_url"]["name"];
}
}}
i got it working.
//POST Video Reviews
public function actionCreate_video_review()
{
$allowedExts = array("jpg", "jpeg", "gif", "png", "mp3", "mp4", "wma","mkv");
$extension = pathinfo($_FILES['video_url']['name'], PATHINFO_EXTENSION);
if ( ($_FILES["video_url"]["type"] == "video/mp4")|| ($_FILES["video_url"]["type"] == "video/x-matroska")&& ($_FILES["video_url"]["size"] < 90000) && in_array($extension, $allowedExts) )
{
if ($_FILES["video_url"]["error"] > 0)
{
return $_FILES["video_url"]["error"];
}
else
{
if (file_exists("upload/" . $_FILES["video_url"]["name"]))
{
echo $_FILES["video_url"]["name"] . " already exists. ";
}
else
{
$model = new \app\models\VideoReview();
$model->video_url = $_FILES["video_url"]["name"];
$model->save();
move_uploaded_file($_FILES["video_url"]["tmp_name"],
\Yii::$app->basePath. '/web/uploads/' . $_FILES["video_url"]["name"]);
return $_FILES["video_url"]["name"];
}
}
}
else
{
return $_FILES["video_url"]["error"] ."Error";
}
}
Related
I have checked email unique in codeigniter. In else past I diplayed error. But the system error is not convenient. how to customise error...
i have tried giveng javascript alert instead of that error message... but after that alert the data are storing in database.. Actually the data should not store in database if the email is not unique..
public function add_applicants() {
// $field_name=$this->input->post('photo');
$data = $this->input->post();
$mobile = $this->db->get_where('applicants',array('mobile_number'=>$this->input->post('mobile_number')));
if($mobile->num_rows()>0)
{
throw new Exception("Mobile Number Already Registered");
}
$email = $this->db->get_where('applicants',array('email_id'=>$this->input->post('email_id')));
if($email->num_rows()>0)
{
throw new Exception("Email_id Already Registered");
}
$school_id= $this->input->post('school_code');
$name_of_exam= $this->input->post('name_of_exam');
$name= $this->input->post('name_candiadte');
switch($name_of_exam){
case '1':
$exam='NMMS';
break;
case '2':
$exam='NTS';
break;
}
$school_code = $this->Welcome_Model->getschoolData($school_id);
if (isset($_FILES['photo']) == 1) {
$config['upload_path'] = FCPATH . 'uploads/'. $school_code->name_of_the_school.'/'. $exam ;
$this->upload_path = $config['upload_path'];
if ($this->validate_upload_path() == TRUE) {
$config['upload_path'] = $this->upload_path;
// print_r($this->upload_path) ;
// die();
}
$config['allowed_types'] = 'jpg';
$config['max_size'] = 2000;
$config['remove_spaces'] = TRUE;
$config['overwrite'] = true;
$config['file_name'] = $name.'-'.date('Ymdhis') . '.jpg';
$file_name = $config['file_name'];
$this->load->library('upload', $config);
$this->upload->initialize($config);
if (!$this->upload->do_upload('photo')) {
$this->upload->display_errors();
}
}
$data['photo'] = $file_name;
$insetapplicants = $this->Welcome_Model->insertApplicants($data);
if ($insetapplicants == 'Success') {
echo "<script>
alert('New Applicants Added Successfully');
// window.location.href='dashboard';
</script>";
}
}
I noticed that in opencart 2.3.0.2 the order confirmation for admin contains the comments from the user, and the email that the user gets doesn't.
The user gets only the text version with the comment, not the HTML version with the comment.
In 2012 2013 the problem was that the comment wasn't passed at all into the emails.
https://github.com/opencart/opencart/pull/94
https://github.com/opencart-ce/opencart-ce/issues/12
It seems the problem was solved only partially.
The solution is:
Edit:
catalog/model/checkout/order.php
Put this code:
$data['ip'] = $order_info['ip'];
$data['order_status'] = $order_status;
if ($comment && $notify) {
$data['comment'] = nl2br($comment);
} else {
$data['comment'] = '';
}
if ($comment) {
if ($order_info['comment']) {
$data['comment'] = nl2br($comment) . '<br/><br/><strong>Comment:</strong><br/>' . $order_info['comment'];
} else {
$data['comment'] = nl2br($comment);
}
} else {
if ($order_info['comment']) {
$data['comment'] = $order_info['comment'];
} else {
$data['comment'] = '';
}
}
instead of:
$data['ip'] = $order_info['ip'];
$data['order_status'] = $order_status;
if ($comment && $notify) {
$data['comment'] = nl2br($comment);
} else {
$data['comment'] = '';
}
Or you can install this mod https://www.opencart.com/index.php?route=marketplace/extension/info&extension_id=32499&filter_search=add%20comment&filter_category_id=8&filter_license=0
I am having a issue with my login page reading a function to login
on my register page which I'm proud to say works perfect
this is my password hash code
$password = password_hash($password, PASSWORD_BCRYPT);
my login page has 2 fields
email &
password
I have re cleaned my code and solved the issue some what
functions are working
when I enter email and password it triggers
Warning! Email or Password Incorrect
plus an error at the top
Notice: Undefined index: password in C:\Program Files (x86)\Zend\Apache2\htdocs\CMS\functions\functions.php on line 249
this is line 249
$db_password = $row['password'];
/* Validate Login */
function validate_login()
{
$errors = [];
if ($_SERVER['REQUEST_METHOD'] == "POST") {
$email = clean($_POST['email']);
$password = clean($_POST['password']);
if (empty($email)) {
$errors[] = "Email Required";
}
if (empty($password)) {
$errors[] = "Password Required";
}
if (! empty($errors)) {
foreach ($errors as $error) {
echo validation_errors($error);
}
} else {
if (login_user($email, $password)) {
redirect("../account/profile.php");
} else {
echo validation_errors("Email or Password Incorrect");
}
}
}
} // End Function
/* User Login */
function login_user($email, $password)
{
$sql = "SELECT user_pwd, uid FROM userss WHERE user_email = '" . escape($email) . "'";
$result = query($sql);
if (row_count($result) == 1) {
$row = fetch_array($result);
$db_password = $row['password'];
if (hash_algos($password) == $db_password) {
return true;
} else {
return false;
}
}
}// End Function
It looks like you are missing a closing bracket for your validate_login() function so it is defining the login_user() function only after the first function is called. Therefore as you progress through your validate_login() function you call the login_user() function before it is created since it is created after the if statement completes.
OK I just figured out the issue
if (hash_algos($password) == $db_password) {
return true;
} else {
return false;
}
changed it to this
if(password_verify($password, $db_password)){
return true;
} else {
return false;
}
OK, I am stumped here. I'm using a Zend script that helps me to upload pictures. It works great, but I am trying to capture the pictures name into a hidden field for a form. I'd like to note that the name changes, so I'd need to get whichever it ends up being put into the hidden field. Here is the Zend script:
<?php
if (isset($_POST['upload'])) {
require_once('scripts/library.php');
try {
$destination = 'xxxxxxxx';
$uploader = new Zend_File_Transfer_Adapter_Http();
$uploader->setDestination($destination);
$filename = $uploader->getFileName(NULL, FALSE);
$uploader->addValidator('Size', FALSE, '90kB');
$uploader->addValidator('ImageSize', FALSE, array('minheight' => 100, 'minwidth' => 100));
if (!$uploader->isValid()) {
$messages = $uploader->getMessages();
} else {
$no_spaces = str_replace(' ', '_', $filename, $renamed);
$uploader->addValidator('Extension', FALSE, 'gif, png, jpg');
$recognized = FALSE;
if ($uploader->isValid()) {
$recognized = TRUE;
} else {
$mime = $uploader->getMimeType();
$acceptable = array('jpg' => 'image/jpeg',
'png' => 'image/png',
'gif' => 'image/gif');
$key = array_search($mime, $acceptable);
if (!$key) {
$messages[] = 'Unrecognized image type';
} else {
$no_spaces = "$no_spaces.$key";
$recognized = TRUE;
$renamed = TRUE;
}
}
$uploader->clearValidators();
if ($recognized) {
$existing = scandir($destination);
if (in_array($no_spaces, $existing)) {
$dot = strrpos($no_spaces, '.');
$base = substr($no_spaces, 0, $dot);
$extension = substr($no_spaces, $dot);
$i = 1;
do {
$no_spaces = $base . '_' . $i++ . $extension;
} while (in_array($no_spaces, $existing));
$renamed = TRUE;
}
$uploader->addFilter('Rename', array('target' => $no_spaces));
$success = $uploader->receive();
if (!$success) {
$messages = $uploader->getMessages();
} else {
$uploaded = "$filename uploaded successfully";
$pic = $filename;
if ($renamed) {
$uploaded .= " and renamed $no_spaces";
}
$messages[] = "$uploaded";
}
}
}
} catch (Exception $e) {
echo $e->getMessage();
}
}
Here I am trying to make the $pic variable not to throw an error for now (on the form page)
if (isset($_POST['upload'])) { } else { $pic = "unknown";}
The $pic variable is what I was trying to have the filename from the zend script copied into. Any feedback is greaaaatly appreciated :)
I recently changed from using mysql to msqli, since then the CRUD functions have all stopped working properly. Please can someone point me in the right direction. Here is my code. sorry for my bad english.
public function create() {
global $database;
$attributes = $this->sanitised_attributes();
$sql = "INSERT INTO ".self::$table_name."(";
$sql .= join(", ", array_keys($attributes));
$sql .= ") VALUES ('";
$sql .= join("', '", array_values($attributes));
$sql .= "')";
if($database->query($sql)) {
$this->id = $database->insert_id();
return true;
} else {
return false;
}
}
Here is the class
class mysqliDatabase {
private $connection;
public $last_query;
private $magic_quotes_active;
private $real_escape_string_exists;
function __construct() {
$this->open_connection();
$this->magic_quotes_active = get_magic_quotes_gpc();
$this->real_escape_string_exists = function_exists("mysqli_real_escape_string");
}
public function open_connection(){
$this->connection = new mysqli(DB_HOST,DB_USER,DB_PASSWORD);
if(!$this->connection) {
die("Database connection failed: " . mysqli_error());
} else {
$db_select = mysqli_select_db($this->connection,'*****');
if (!$db_select) {
die("Database selection failed: " . mysqli_error());
} else { echo "connected";}
}
}
public function close_connection(){
if(isset($this->connection)) {
mysqli_close($this->connection);
unset($this->connection);
}
}
public function query($sql) {
$this->last_query = $sql;
$result = mysqli_real_query($this->connection, $sql);
$this->confirm_query($result);
return $result;
}
public function escape_value($value) {
if($this->real_escape_string_exists) {
//undo any magic quote effects so mysqli_real_escape can do the work
if($this->magic_quotes_active){ $value = stripslashes($value);}
$value = mysqli_escape_string($this->connection, $value);
} else {
//if magic quotes aren't already on then add slashes manually
if(!$this->magic_quotes_active) { $value = addslashes($value);
}
//if magic quotes are active, then the slashes already exist
}
return $value;
}
public function fetch_array($result_set) {
return mysqli_fetch_array($result_set);
}
public function num_rows($result_set) {
return mysqli_num_rows($result_set);
}
public function insert_id() {
//get the last id inserted over the current db connection
return mysqli_insert_id($this->connection);
}
public function affected_rows() {
return mysqli_affected_rows($this->connection);
}
private function confirm_query($result) {
if(!$result) {
$output = "Database query failed " . mysqli_error($this->connection) . "<br
/><br />";
$output .= "last SQL query: " . $this->last_query;
die($output);
}
}
The problem is not in this function, but in the database class. You would need to share that one to be able to get help.