Image upload in Shiny - file-upload
I have been trying to figure out how to upload an image from a local computer through a shiny app, but I'm having trouble determining how to access the image in order to use it in the server side code and to then save it to a remote location. Right now, I have tried both fileInput() and custom HTML code using jQuery (shown below).
<!-- Google web fonts -->
<link href='http://fonts.googleapis.com/css?family=PT+Sans+Narrow:400,700' rel='stylesheet' />
<!-- The main CSS file -->
<link href='txt/assets/css/style.css' rel='stylesheet' />
<form id='upload' method='post' action='txt/upload.php' enctype='multipart/form-data'>
<div id='drop'>
Drop Here
<a>Browse</a>
<input type='file' name='upl' multiple />
</div>
<ul>
<!-- The file uploads will be shown here -->
</ul>
</form>
<!-- JavaScript Includes -->
<!-- <script src='https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js'></script> -->
<script src='txt/assets/js/jquery.knob.js'></script>
<!-- jQuery File Upload Dependencies -->
<script src='txt/assets/js/jquery.ui.widget.js'></script>
<script src='txt/assets/js/jquery.iframe-transport.js'></script>
<script src='txt/assets/js/jquery.fileupload.js'></script>
<!-- Our main JS file -->
<script src='assets/js/script.js'></script>
This is the upload.php:
// A list of permitted file extensions
$allowed = array('png', 'jpg', 'gif','zip');
if(isset($_FILES['upl']) && $_FILES['upl']['error'] == 0){
$extension = pathinfo($_FILES['upl']['name'], PATHINFO_EXTENSION);
if(!in_array(strtolower($extension), $allowed)){
echo '{"status":"error"}';
exit;
}
if(move_uploaded_file($_FILES['upl']['tmp_name'], 'uploads/'.$_FILES['upl']['name'])){
echo '{"status":"success"}';
exit;
}
}
echo '{"status":"error"}';
exit;
And this is the server and ui code for the app.
shinyServer(function(input, output) {
output$your_species <- renderText({
current_species
})
output$current_sp <- renderText({
current_species
})
# output$your_image <- renderImage({
# input$image_upload
# }, deleteFile = FALSE)
source("pages/main_page.R")
source("pages/help_page.R")
header <- dashboardHeader(title="End. Sp. Images")
sidebar <- dashboardSidebar(disable=TRUE)
body <- dashboardBody(
main_page,
help_page
)
dashboardPage(header, sidebar, body, skin="blue")
main_page <- {
fluidPage(
column(1,
img(src="01_DOW_LOGO_COLOR_100.png"),
tags$hr()#,
),
column(11,
tabsetPanel(
tabPanel(title="Main",
tags$h3(textOutput("your_species"), style=make_bold()),
fluidRow(
column(4,
box(title="Image information",
collapsible=TRUE,
status="primary",
solidHeader=TRUE,
height=NULL,
width=NULL,
textInput("species",
label="Species",
value=current_species
),
textInput("img_src",
label="Image source",
value="http://"
),
selectInput("license",
label="Image license",
choices=list_of_licenses,
selected="Select..."
),
textInput("attribution",
label="Image attribution",
value="To whom should attribution be given?"
),
tags$hr(),
tags$p("Drop photo on button or click to choose",
style="color:gray"
),
# fileInput("image_upload",
# label="Photo upload"
# ),
tags$div(
HTML(html_txt)
),
submitButton("Submit")
# htmlOutput("wikimedia_embed")
)
),
column(5,
box(title="Your image",
collapsible=TRUE,
status="primary",
solidHeader=TRUE,
height=500,
width=NULL,
imageOutput("your_image",
height=NULL,
width="100%"
)
)
),
column(3,
tags$p("Some search options", style=make_18_bold()),
tags$p("Pre-formatted searches", style="color:gray"),
infoBox(
title="First option",
value=tags$a("Wikimedia",
href=wiki_srch,
target='_blank'),
icon=icon("picture-o"),
color="light-blue",
width=NULL
),
# infoBox(
# title="Second option",
# value=tags$a("CC Search",
# # href="http://search.creativecommons.org",
# href=cc_search,
# target='_blank'),
# icon=icon("picture-o"),
# color="light-blue",
# width=NULL
# ),
infoBox(
title="Second option",
value=tags$a("Google Image Search",
href=goog_srch,
target='_blank'),
icon=icon("picture-o"),
color="light-blue",
width=NULL
), #,
tags$p("Creative Common portal", style="color:gray"),
infoBox(
title="Check here too!",
value=tags$a("CC Search",
href="http://search.creativecommons.org",
target='_blank'),
icon=icon("picture-o"),
color="light-blue",
width=NULL
)
)
)
)
)
)
)
}
The HTML completely breaks the style of the upload portion of the app, but I think that is simply because of a poor directory structure. However, with both of these methods I can't figure out how to access the uploaded file. The "Choose file" button works and it shows that the file has been uploaded, but I don't know what to call in the server side that will allow me to both save the file remotely and use that file in an imageRender().
Any help for how to access the uploaded file is much appreciated!
Related
How to replace some values inside a specific tag in a index.html file using a cypress automation test
Currently, I'm working with Cypress test automation. I have an index.html file inside cypress/downloads/sample/index.html. The index.html file has the below structure. <html> <head> <style type="text/css"> </style> </head> <body> <script src="https://test"></script> <script src="https://test2"></script> <!-- sample Config --> <script> const authConfig = { clientID: "sample value", signInRedirectURL: "sample value", serverOrigin: "sample value" }; </script> </body> </html> I will get copy the content inside the script tag which will be displayed in an application UI using a button click for the copy operation so the copied content will be as below <script> const authConfig = { clientID: "abcd1234", signInRedirectURL: "https://localhost:8000", serverOrigin: "https://localhost:8000" }; </script> Method written for copy and paste operation is as below: static CopyConfigs() { cy.get(COPY_ICON).click(); cy.wait(7000); } static pasteoperation(Location){ cy.task("getClipboard").then((value) => { cy.writeFile(Location + "/sample/index.html", value); }); } writeFile will replace the whole index.html file content Need help on I want to replace(paste) the content copied to the index.html file by replacing only the script tag(related to authConfig) content inside the index.html file without replacing the whole index.html file content. So that the values for clientID, signInRedirectURL, and serverOrigin inside the script tag of index.html file will have the new values. Is it possible to read the index.html file and capture the script tag and replace the <script> tag content using Cypress automation? Appreciate your support on how to achieve this.
create my own directory in html with download links
I was trying to create an online webshare but i'm unable to make a page which will automatically add or remove files from the site when done so. Please help me in resolving this problem. And I'm not able to link the PHP code to the html page to execute, please help me in creating the html and PHP in my already built design pages so that i can complete my project. The Php Of The Page Goes As Follows <html> <body style="background:#e9e9e9; font-family:Verdana; font-size:180%"> <head> <p style="text-align:center; size:20%">Download Now! <br>No Need of Internet!</p> </head> <div style="background:white; margin-right:2%; margin-left:2%; font-size:150%"> <font color="cornflowerblue">Owais</font> shared some files with you. <hr> Files <hr> <?php if ($handle = opendir('C:\Users\makro\Documents\Share\Send')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $thelist .= '<li>'.$file.'</li>'; } } closedir($handle); } ?> <h1>List of files:</h1> <ul><?php echo $thelist; ?></ul> </div> </body> </html>
Requests or Urllib - Login in a website, send download request to url, and save as xlsx
I am going crazy with the following problem. What I want to do is login into a website, download a file, while saving the download request as an xlsx. I am pretty sure I need to use the requests librarybut don't seem to know exactly how to do it. This is what I have so far : import requests # URL Data login_url = 'https://reporting.integralplatform.com/uaa/login#/' report_url = 'https://integralplatform.com/home/brand-safety/firewall?period=%5B2016-09-01..2017-02-19%5D&publisher=all&placement=all&deliveryEnvironment=%5Bdesktop%5D&includeCampaign=true&campaigns=52921%3A52919%3A52931%3A52922%3A52933%3A54272%3A52934%3A54370%3A54363%3A54372%3A54362%3A54369%3A54368%3A54366%3A54365%3A54367&includePlacement=true&grouping=placementName&dateGroup=daily' download_url = 'https://integralplatform.com/reportingservice/api/teams/3236/fw/campaigns/52921%253A52919%253A52931%253A52922%253A52933%253A54272%253A52934/report.xls?period=%5B2016-09-01..2017-02-19%5D&cutoff=250&mediaType=mixed&groups=%5Bcamp%3Apub%3Aplac%3Adaily%5D&tabs=%5Bfirewall%5D&settings=%7B%22Selected%20Report%22%3A%22Firewall%20Activity%22%2C%22Group%20Dates%20By%22%3A%22Day%22%2C%22Report%20By%22%3A%22Campaign%22%2C%22Campaign%22%3A%22%25%25CAMPAIGN_NAMES%25%25%22%2C%22Media%20Partner%22%3A%22All%22%2C%22Placement%22%3A%22Yes%22%2C%22Geo%20Level%22%3A%22Country%22%2C%22Cutoff%22%3A%22250%22%7D' # Payload payload = { "username" : 'my username' , "password": 'my password', "_csrf_uaa": "507be70c-d4ff-4ea7-a3bf-d45cad3faa47", } # Authenticate login = requests.post(login_url, data=payload) # Download File download = requests.post(download_url, data=payload) However, while I look at both login.content and download.content it seems like I fail to even login as the result is : b'<!DOCTYPE html>\n<html lang="en" ng-app="iasLogin">\n<head>\n\n <meta charset="UTF-8">\n\n <title>IAS Login</title>\n\n\n <!-- Start Vendor CSS -->\n <link rel="stylesheet" href="css/ias-app-vendor.min.css">\n <!-- End Vendor CSS -->\n\n <!-- Start IAS CSS -->\n <link rel="stylesheet" href="css/ias-app.min.css">\n <!-- End IAS CSS -->\n\n</head>\n<body>\n\n <ias-headers></ias-headers>\n\n <div ui-view></div>\n\n <!-- Start Vendor JS -->\n <script src="js/ias-app-vendor.min.js"></script>\n <!-- End Vendor JS -->\n\n <!-- Start IAS JS -->\n <script src="js/ias-app.min.js"></script>\n <!-- End IAS JS -->\n\n</body>\n</html>' What it seems to me is that I am clearly doing something wrong when it comes to the payload. However, I don't know how to fix it. To clarify, the difference between report_url and download_url is that download_url is the url I receive when I right click the download button. The parameters are fixed. Thanks for all the help
You'll likely need to include headers and form data that the page submits along with your current payload.
Install ckeditor in YII framework
I am using Yii Framework version 1.1.14. I am able to install FCK editor but I want to use ck editor. I download files from this links http://www.yiiframework.com/extension/the-ckeditor-integration/ and upload files on location but i get this error check image I am using this code in my view <?php $this->widget('application.extensions.ckeditor.CKEditorWidget',array( 'model'=>$model, # Data-Model (form model) 'attribute'=>'content', # Attribute in the Data-Model 'height'=>'400px', 'width'=>'100%', 'toolbarSet'=>'Basic', # EXISTING(!) Toolbar (see: ckeditor.js) 'ckeditor'=>Yii::app()->basePath.'/../ckeditor/ckeditor.php', # Path to ckeditor.php 'ckBasePath'=>Yii::app()->baseUrl.'/ckeditor/', # Relative Path to the Editor (from Web-Root) 'css' => Yii::app()->baseUrl.'/css/index.css', # Additional Parameters ) ); ?>
Download CKEditor from http://ckeditor.com/download (Select full package) and put it in your root directory (You can put it any where according to you) Add this is your view file <script src="<?php echo Yii::app()->baseUrl.'/ckeditor/ckeditor.js'; ?>"></script> <script type="text/javascript"> CKEDITOR.replace( 'Articles_meta_description'); </script> Where Articles_meta_description is id of input fields If you want add image upload in ckeditor you can download KCfinder from this link http://kcfinder.sunhater.com/download and put it in your root directory (you can put it any where according to you) Set upload path into session : in your view file $_SESSION['KCFINDER']['disabled'] = false; // enables the file browser in the admin $_SESSION['KCFINDER']['uploadURL'] = Yii::app()->baseUrl."/uploads/"; // URL for the uploads folder $_SESSION['KCFINDER']['uploadDir'] = Yii::app()->basePath."/../uploads/"; // For ckeditor with image upload <script type="text/javascript"> CKEDITOR.replace( 'Articles_meta_description', { // input field id filebrowserBrowseUrl: '<?php echo Yii::app()->baseUrl; ?>/kcfinder/browse.php?type=files', filebrowserImageBrowseUrl: '<?php echo Yii::app()->baseUrl; ?>/kcfinder/browse.php?type=images', filebrowserFlashBrowseUrl: '<?php echo Yii::app()->baseUrl; ?>/kcfinder/browse.php?type=flash', filebrowserUploadUrl: '<?php echo Yii::app()->baseUrl; ?>/kcfinder/upload.php?type=files', filebrowserImageUploadUrl: '<?php echo Yii::app()->baseUrl; ?>/kcfinder/upload.php?type=images', filebrowserFlashUploadUrl: '<?php echo Yii::app()->baseUrl; ?>/kcfinder/upload.php?type=flash' }); </script>
Opencart - Upload Specific File Type
I am using OpenCart 1.5.6 and have two options for the customer to upload files to a product (image and video). When the users clicks upload I would like them to only be able to select specific file types from their computer while they browse for the files. So instead of "All Files" in the browser window, I want it to only allow .png, .jpg, .jpeg, .pdf, etc. for the image upload and for the video file I just want it to look for .mp4, .mov, .flv. Here is an example: http://jsfiddle.net/VCdvA/ I have tried to use the accept attribute according to this post but it doesn't work. Here is my code for the product.tpl: <input type="button" accept="video/*,image/*" value="<?php echo $button_upload; ?>" id="button-option-<?php echo $option['product_option_id']; ?>" class="button" > <input type="hidden" name="option[<?php echo $option['product_option_id']; ?>]" value="" /> I think that the problem is that it is type="button" and not type="file". Is there another way to limit the upload file type within the OpenCart product page?
The problem is the jQuery plugin used. It is AjaxUpload which seems to be taken over by different developer (completely) and reworked (completely) and the links to the original (old) documentation are dead (completely). Well, after exploring that jQuery plugin I have found out that it works this way: in the ptoduct.tpl You can see: <?php foreach ($options as $option) { ?> <?php if ($option['type'] == 'file') { ?> <script type="text/javascript"><!-- new AjaxUpload('#button-option-<?php echo $option['product_option_id']; ?>', { //... }); //--></script> <?php } ?> <?php } ?> This means that for each option of type file this AjaxUpload is instanciated. Basically it only creates a DIV containing INPUT of type FILE with 0 opacity that is rendered above the Upload File button. This means that when user clicks on Upload File he clicks on the INPUT of type FILE instead (without knowing this). Now, looking at the code I can see that there is no possibility to set this accept="image/*" attribute because there is no support for this (original code): _createInput: function(){ var self = this; var input = document.createElement("input"); input.setAttribute('type', 'file'); input.setAttribute('name', this._settings.name); addStyles(input, { // ... }); // ... }, So now if You'd like to add support for this, You'd need to change this code to this (file: catalog/view/javascript/jquery/ajaxupload.js, around line 350): var input = document.createElement("input"); input.setAttribute('type', 'file'); input.setAttribute('name', this._settings.name); if (this._settings.accept) { input.setAttribute('accept', this._settings.accept); } And change the code for plugin initializiation in product.tpl to: <?php foreach ($options as $option) { ?> <?php if ($option['type'] == 'file') { ?> <script type="text/javascript"><!-- new AjaxUpload('#button-option-<?php echo $option['product_option_id']; ?>', { <?php if ($option['product_option_id'] == <IMAGE_FILE_OPTION_ID>) { ?> accept: 'image/*', <?php } else if ($option['product_option_id'] == <VIDEO_FILE_OPTION_ID>) { ?> accept: 'video/*', <?php } ?> //... }); //--></script> <?php } ?> <?php } ?> This should be enough.