Wordpress , Where file can I find this function - wordpress-theming

Wordpress , Where file can I find this functionenter image description here

Related

How to insert a downloaded image into HTML code?

I'm a junior dev trying to build a portfolio site and want to upload a pic of me that is already downloaded on my PC. When I type in an src of an image that exists somewhere online it clearly appears on my live server but when I insert the src of an image existing somewhere within my PC's local drives it doesn't appear. Is it that I have to upload this image somewhere online (e.g. google drive) and then type in its new src or is there a way to upload offline images?
Hope someone can help!
Create a folder called assets in your project and add all images and any other files you may need. Then add the path to your image in src
there are some options to do it.
The more preferable is creating a folder let's say Src or Images. Then download any images into the folder using classes from a namespace System.IO (Path, Directory, ...). But be sure that your image names+extension are unique. Also, you can store in a DB file name and path the related file on your server and userId to be sure who added the file.
Another option is to store byte arrays in DB. Adding action for returning your file
public async Task<AcitonResult> GetImage(int id)
{
byte[] imgBytes = await GetImageFromDbById(id);
if (imgBytes == null)
return NotFound();
return File(imgBytes, "image/jpg");
}
Asking an image
<img src="/**YourControllerName**/GetImage/**#imageId**">

How to save a created html file to a specific location by giving a path

I have created a html file of my results using .to_html() function.By default the html file saves to the root location of your project folder.But what if i want to save it to the specific location?How to give a path to the created folder .Im using flask to connect python to html.
You can access the root path of the flask through app.root_path.
So let's say your folder name is myHtmlFiles. So we can save the files like below:
file.save(os.path.join(app.root_path, "myHtmlFiles", "hey.html"))
You can also take a look at app.config, you can put your folder path here and use it anywhere in the aplplication.

How do I add JSON data into a wordpress page?

I am trying to view a json file on a worpdress themed page. I have downloaded the json data file. I uploaded the file to my Wordpress site under the root directory. I have tried multiple ways to show the data but nothing is working. How do I show the data and then format it?
For decoration, it depends what the data is. To get your data in to an array variable, if it's in a file already uploaded, I would do something like this in PHP:
$data_json = file_get_contents("path/to/the/json/file");
$data_arr = json_decode($data_json, true);
var_dump($data_arr);

html file download on node server

Within my public folder on my node.js server I have a standard html website set up.
Im trying to download files from a webpage using
Download
but i keep getting:
my folder structure looks like this(shortened)
Files
-Solar.zip
public
-project.html
Where project.html is where I have the button to download.Should i be using a get instead? or is it not html related at all?
You need to add full path to zip file in href attribute:
Download
download attribute just allows you to set a separate file download name than the actual link. For example:
Download
will start downloading file a.zip but will rename it to b.zip

How to upload files from a plugin to wordpress media library?

I need to developed a front-end drag and drop plug in. First I collect the html5 drag and droping code.
Download the source code in zip format - https://github.com/Mashpy/html5-drag-and-drop-upload/archive/master.zip
Put the files in localhost and open. If you upload files it will be uploades in "uploads" folder. Because I put code in " /js/mashpy.js " that this time "upload.php" file will be loaded and it will send the files in "uploads" folder.
That means this process work something like this -
index.html -- js/mashpy.js -- upload.php -- send file to "uploads" -- dump.php will show the result that upload successfully.
Now I have to developed a front-end drag and drop plug in. But I don't know how to upload files in wordpress media library. In this source code upload.php works which send files to "uploads" folder. But what happened in wordpress? How to send files to wordpress media library?
You can't simply upload files to wp-content/uploads/. They won't show up in Media Library. You need to use WordPress function media_handle_upload($file,$post_id), passing 0 as post ID (so, it's not attached to any post/page).
Something like:
if ($_FILES) {
foreach ($_FILES as $file => $array) {
if ($_FILES[$file]['error'] !== UPLOAD_ERR_OK) {
return "upload error : " . $_FILES[$file]['error'];
}
$attach_id = media_handle_upload( $file, 0 );
}
}
You can study this plugin to see how it does it: Add From Server. And also research in WordPress Answers for examples of this function usage.