Adding a progress bar when Uploading local files using API - api

API Documentation: https://doodstream.co/api-docs#local-upload
My code seems working but there's no indicator how many time left before download is finished
HTML
<form enctype="multipart/form-data" action="upload.php" id="form" method="post" align="center">
<div>
<label>Custom File Name: </label><br>
<input type="text" placeholder="File Name" name="fname" minlength="3" required/>
</div>
<br><br>
<div>
<label>Select video: </label><br>
<input type="file" name="file" accept="video/*" required/><br>
</div>
<br>
<input name="submit" type="submit" value="Upload"/>
</form>
upload.php
<?php
if(!empty($_FILES)){
$tempfile = $_FILES["file"]["tmp_name"]; //Temporary file location on server
$fname = $_POST["fname"]; //Custom File name input
$type = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION); //File extention
$name = $fname . '.' . $type; //Complete file name with extention to be used in API
require('doodstream.php'); //Unofficial Library from GitHub
$ds = new DoodstreamAPI();
$key = "MY-API-KEY"; //Insert API key here
$ds->Setup($key);
$result = $ds->Upload($tempfile, $type, $name);
print_r($result);
}
else{
die('No file uploaded');
}
?>
Is there any method to make this possible? I just read the documentation and there's only an "After upload response"

Related

Why do I keep seeing the undefined index error for line 13 ('file')?

I am trying to create a simple drag and drop page using php. When I click the "submit" button, I get an error: Notice: Undefined index: file in C:\xampp\htdocs\phpfiles\DragAndDrop\includes\gallery-upload.inc.php on line 13. Why is it not reading the "file" index from the htmlphp?
Here is the HTML and PHP code:
enter code here
<!--continuted from HTML page-->
</section>
<?php
$_SESSION['username'] = "Admin";
if (isset($_SESSION['username'])) {
echo '<div class="gallery-upload">
<form action="includes/gallery-upload.inc.php" method="post" enctype="mutipart/form-data">
<input type="text" name="filename" placeholder="File Name...">
<input type="text" name="filetitle" placeholder="Image Title...">
<input type="text" name="filedesc" placeholder="Image description...">
<input type="file" name="file">
<button type="submit" name="submit">Upload</button>
</form>
</div>';
}
?>
</main>
</body>
</html>
<!--and the php page-->
<?php
if (isset($_POST['submit'])) {//checks submit form and posts the info
$newFileName = $_POST['filename'];
if (empty($_POST['filename'])) { //if filename is emptly
$newFileName = "gallery"; //if filename is empty, generates name
} else {
$newFileName = strtolower(str_replace(" ", "-", $newFileName)); //if spaces are in the name, creates stringholder
}
$imageTitle = $_POST['filetitle'];
$imageDesc = $_POST['filedesc'];
$file = $_FILES['file'];
}
?>
You have a typo:
mutipart/form-data
Should be
multipart/form-data

What exact code is needed for Wordpress/Woocommerce login/sign up pages [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am creating a small e-commerce website using wordpress & woocommerce but I'm not really understanding the login/signup abilities for users. I just want users who visit the site to be able to click a link on the home page where they can sign up and login (with the option to reset their passwords) and in return those customer details are saved within the user data for the wordpress admin to be able to see. What is the coding for this? Because I can't seem to get into a lot of these plugins.
<?php
global $wpdb, $user_ID;
$firstname='';
$lastname='';
$username='';
$email='';
//if looged in rediret to home page
if ( is_user_logged_in() ) {
wp_redirect( get_option('home') );// redirect to home page
exit;
}
if(sanitize_text_field( $_POST['com_submit']) != ''){
$firstname=sanitize_text_field( $_REQUEST['com_firstname'] );
$lastname=sanitize_text_field( $_REQUEST['com_lastname']);
$username = sanitize_text_field( $_REQUEST['com_username'] );
$email = sanitize_text_field( $_REQUEST['com_email'] );
$password = $wpdb->escape( sanitize_text_field( $_REQUEST['com_password']));
$status = wp_create_user($username,$password,$email);
if (is_wp_error($status)) {
$error_msg = __('Username or Email already registered. Please try another one.','twentyten');
}
else{
$user_id=$status;
update_user_meta( $user_id,'first_name', $firstname);
update_user_meta( $user_id,'last_name', $lastname);
//code to auto login start
$alar_enable_auto_login= get_option('alar_enable_auto_login');
if($alar_enable_auto_login==''){
$alar_enable_auto_login= 'true';
}
if($alar_enable_auto_login == 'true'){
if(!is_user_logged_in()){
$secure_cookie = is_ssl();
$secure_cookie = apply_filters('secure_signon_cookie', $secure_cookie, array());
global $auth_secure_cookie;
$auth_secure_cookie = $secure_cookie;
wp_set_auth_cookie($user_id, true, $secure_cookie);
$user_info = get_userdata($user_id);
do_action('wp_login', $user_info->user_login, $user_info);
}
}
//code to auto login end
wp_redirect( get_option('home') );// redirect to home page
exit;
}
}
?>
<div class="alar-registration-form">
<div class="alar-registration-heading">
<?php _e("Registration Form",'');?>
</div>
<?php if($error_msg!='') { ?><div class="error"><?php echo $error_msg; ?></div><?php } ?>
<form name="form" id="registration" method="post">
<div class="ftxt">
<label><?php _e("First Name :",'');?></label>
<input id="com_firstname" name="com_firstname" type="text" class="input" required value=<?php echo $firstname; ?> >
</div>
<div class="ftxt">
<label><?php _e("Last name :",'');?></label>
<input id="com_lastname" name="com_lastname" type="text" class="input" required value=<?php echo $lastname; ?> >
</div>
<div class="ftxt">
<label><?php _e("Username :",'');?></label>
<input id="com_username" name="com_username" type="text" class="input" required value=<?php echo $username; ?> >
</div>
<div class="ftxt">
<label><?php _e("E-mail :",'');?> </label>
<input id="com_email" name="com_email" type="email" class="input" required value=<?php echo $email; ?> >
</div>
<div class="ftxt">
<label><?php _e("Password :",'');?></label>
<input id="password1" name="com_password" type="password" required class="input" />
</div>
<div class="ftxt">
<label><?php _e("Confirm Password : ",'');?></label>
<input id="password2" name="c_password" type="password" class="input" />
</div>
<div class="fbtn"><input type="submit" name='com_submit' class="button" value="Register"/> </div>
</form>
</div>
<?php
}
//add registration shortcoode
add_shortcode( 'registration-form', 'alar_registration_shortcode' );
// function to login Shortcode
function alar_login_shortcode( $atts ) {
//if looged in rediret to home page
if ( is_user_logged_in() ) {
wp_redirect( get_option('home') );// redirect to home page
exit;
}
global $wpdb;
if(sanitize_text_field( $_GET['login'] ) != ''){
$login_fail_msg=sanitize_text_field( $_GET['login'] );
}
?>
<div class="alar-login-form">
<?php if($login_fail_msg=='failed'){?>
<div class="error" align="center"><?php _e('Username or password is incorrect','');?></div>
<?php }?>
<div class="alar-login-heading">
<?php _e("Login Form",'');?>
</div>
<form method="post" action="<?php echo get_option('home');?>/wp-login.php" id="loginform" name="loginform" >
<div class="ftxt">
<label><?php _e('Login ID :','');?> </label>
<input type="text" tabindex="10" size="20" value="" class="input" id="user_login" required name="log" />
</div>
<div class="ftxt">
<label><?php _e('Password :','');?> </label>
<input type="password" tabindex="20" size="20" value="" class="input" id="user_pass" required name="pwd" />
</div>
<div class="fbtn">
<input type="submit" tabindex="100" value="Log In" class="button" id="wp-submit" name="wp-submit" />
<input type="hidden" value="<?php echo get_option('home');?>" name="redirect_to">
</div>
</form>
</div>
just copy and past This code where do you want to add register login form

Inserting into the db with PDO

<form action="uploads.php" method="post" enctype="multipart/form-data" id="upload" class="upload">
<fieldset>
<legend>Upload</legend><br/>
Title: <input type="text" name="name" id="name" class="name" required> <br/><br/>
<textarea name="description" rows="6" cols="35" maxlength="120"></textarea><br/>
<input type="file" id="file" name="file[]" required multiple> <br/>
<input type="submit" id="submit" name="submit" value="Upload">
</fieldset>
<div class="bar">
<span class="bar-fill" id="pb"><span class="bar-fill-text" id="pt"></span></span>
</div>
<div id="uploads" class="uploads">
Uploaded file links will appear here.
</div>
<?php
// configuration
$dbhost = "localhost";
$dbname = "blog";
$dbuser = "root";
$dbpass = "pass";
// database connection
$conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);
// new data
$name = 'name';
$mime = 'mime';
$data = 'data';
$size = 'size';
$description = 'description';
$created = 'created';
$url = 'url';
// query
$sql = "INSERT INTO videos (name,mime,data,size,description,created,url) VALUES (:name,:mime,:data,:size,:description,:created,:url)";
$q = $conn->prepare($sql);
$q->execute(array(':name'=>$name,
':mime'=>$mime,
':data'=>$data,
':size'=>$size,
':description'=>$description,
':created'=>$created,
':url'=>$url));
?>
I'm not so good with PDO, I can get videos to upload to my db, but I can't take in a name or anything. It just shows: name, description, size is 0 and etc. I've watched a few tutorials, but none of them show how to add it by what the user names it or describes it as, only what they put into the values goes to the database. I've also searched around on here and many other websites, but no luck.

How to get additional social icons in prestashop block social module

In my prestashop site i have implemented block social module and by default i can able to get facebook,twitter and rss social icons.How can i get addtional social icons such as google,pinterest and you tube.
you have to edit the blocksocial.php
this code i have added the google link
find a "getContent" method on your blocksocial.php in your module folder
and change it to
public function getContent()
{
// If we try to update the settings
$output = '';
if (isset($_POST['submitModule']))
{
Configuration::updateValue('blocksocial_facebook', (($_POST['facebook_url'] != '') ? $_POST['facebook_url']: ''));
Configuration::updateValue('blocksocial_twitter', (($_POST['twitter_url'] != '') ? $_POST['twitter_url']: ''));
Configuration::updateValue('blocksocial_rss', (($_POST['rss_url'] != '') ? $_POST['rss_url']: ''));
Configuration::updateValue('blocksocial_google', (($_POST['google_url'] != '') ? $_POST['google_url']: ''));
$this->_clearCache('blocksocial.tpl');
$output = '<div class="conf confirm">'.$this->l('Configuration updated').'</div>';
}
return '
<h2>'.$this->displayName.'</h2>
'.$output.'
<form action="'.Tools::htmlentitiesutf8($_SERVER['REQUEST_URI']).'" method="post">
<fieldset class="width2">
<label for="facebook_url">'.$this->l('Facebook URL: ').'</label>
<input type="text" id="facebook_url" name="facebook_url" value="'.Tools::safeOutput((Configuration::get('blocksocial_facebook') != "") ? Configuration::get('blocksocial_facebook') : "").'" />
<div class="clear"> </div>
<label for="twitter_url">'.$this->l('Twitter URL: ').'</label>
<input type="text" id="twitter_url" name="twitter_url" value="'.Tools::safeOutput((Configuration::get('blocksocial_twitter') != "") ? Configuration::get('blocksocial_twitter') : "").'" />
<div class="clear"> </div>
<label for="rss_url">'.$this->l('RSS URL: ').'</label>
<input type="text" id="rss_url" name="rss_url" value="'.Tools::safeOutput((Configuration::get('blocksocial_rss') != "") ? Configuration::get('blocksocial_rss') : "").'" />
<div class="clear"> </div>
<label for="rss_url">'.$this->l('Goolge Plug: ').'</label>
<input type="text" id="google_url" name="google_url" value="'.Tools::safeOutput((Configuration::get('blocksocial_google') != "") ? Configuration::get('blocksocial_google') : "").'" />
<div class="clear"> </div>
<br /><center><input type="submit" name="submitModule" value="'.$this->l('Update settings').'" class="button" /></center>
</fieldset>
</form>';
}
and after that find "hookDisplayFooter" method
and change it to
public function hookDisplayFooter()
{
if (!$this->isCached('blocksocial.tpl', $this->getCacheId()))
$this->smarty->assign(array(
'facebook_url' => Configuration::get('blocksocial_facebook'),
'twitter_url' => Configuration::get('blocksocial_twitter'),
'rss_url' => Configuration::get('blocksocial_rss'),
'google_url' => Configuration::get('blocksocial_google')
));
return $this->display(__FILE__, 'blocksocial.tpl', $this->getCacheId());
}
last you need to change the template file.
if your template file override by your theme means find a "module" folder from the theme foler and find "blocksocial" folder and edit the blocksocial.tpl
if it is not override by your theme file means you can edit the blocksocial.tpl in you module folder
the changes should be
<div id="social_block">
<p class="title_block">{l s='Follow us' mod='blocksocial'}</p>
<ul>
{if $facebook_url != ''}<li class="facebook">{l s='Facebook' mod='blocksocial'}</li>{/if}
{if $twitter_url != ''}<li class="twitter">{l s='Twitter' mod='blocksocial'}</li>{/if}
{if $rss_url != ''}<li class="rss">{l s='RSS' mod='blocksocial'}</li>{/if}
{if $google_url != ''}<li class="google">{l s='Google' mod='blocksocial'}</li>{/if}
</ul>
</div>
You can use the social login module to add social icons for sharing as well as for login process from link below:
http://loginradius-social-plugins.s3.amazonaws.com/Prestashop/v1.5/sociallogin.zip
It is working good at my website.
This looks incomplete to me. Do you not have to also change 'sprite_pict_social_block.png' to get the additional logos?

Insert multiple files into mysql

I am trying to create a form whereby I can select multiple files (they will be pdfs) and insert the file and the file's name into the database.
Html form works beautifully:
<form action="" method="POST" enctype="multipart/form-data">
<input type="file" name="files[]" multiple/>
<input type="submit"/>
</form>
But I can't seem to make the php work with it:
if(isset($_POST['files[]'])){
$file_name = $_POST['files[]']['name'];
$file_size =$_POST['files[]']['size'];
$file_type=$_POST['files[]']['type'];}
$query="INSERT INTO upload_data (`FILE_NAME`,`FILE_SIZE`,`FILE_TYPE`) VALUES('$file_name','$file_size','$file_type'); ";
I also don't know how to insert the actual file, as opposed to just its properties. Any ideas?
UPDATE:
I got how to upload multiple files, and also multiple file names, but I cannot do both at the same time. Still need help. The code is:
<form action="" method="POST" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
<input type="file" name="files[]" multiple/>
<input type="submit"/>
</form>
if(isset($_FILES['files'])){
foreach ($_FILES['files']['name'] as $filename) {
$query=mysql_query("INSERT INTO practice (name) VALUES('$filename')", $c) or die("six");
}
}
and
if(isset($_FILES['files'])){
foreach ($_FILES['files'] as $file) {
$query=mysql_query("INSERT INTO practice (file) VALUES('$file')", $c) or die("six");
}
}
To get information about uploaded files, you need to use the $_FILES variable instead of the $_POST variable : http://www.php.net/manual/en/features.file-upload.post-method.php