wordPress 如何保存插件中上传的图片到对应插件的目录下面?
开发了个插件中有个上传图片的功能,插件下面有个目录是img保存图片的,想问如何课一保存上传的啊图片到这个目录?
<code>// Check that the nonce is valid, and the user can edit this post. if ( isset($_POST['my_image_upload_nonce'], $_POST['post_id']) && wp_verify_nonce($_POST['my_image_upload_nonce'], 'my_image_upload') && current_user_can('edit_post', $_POST['post_id']) ) { // The nonce was valid and the user has the capabilities, it is safe to continue. // These files need to be included as dependencies when on the front end. require_once(ABSPATH . 'wp-admin/includes/image.php'); require_once(ABSPATH . 'wp-admin/includes/file.php'); require_once(ABSPATH . 'wp-admin/includes/media.php'); // Let WordPress handle the upload. // Remember, 'my_image_upload' is the name of our file input in our form above. $url=WPWSL_PLUGIN_URL . '/img/' . $imageSize . '.png'; // update_option('upload_path',WP_CONTENT_DIR.'/uploads'); update_option('upload_path',WPWSL_PLUGIN_URL.'/img/'); $attachment_id = media_handle_upload('my_image_upload', $_POST['post_id']); if (is_wp_error($attachment_id)) { // There was an error uploading the image. echo "<p>There was an error uploading your file.</p>"; } else { // The image was uploaded successfully! echo "<p>The image was uploaded successfully!</p>"; add_filter('img', $attachment_id); // add_filter('img', 'custom_upload_directory'); } } else { echo "<p>The security check failed, maybe show the user an error</p>"; // The security check failed, maybe show the user an error. }</code>
列表项目
<td>
<input type="file" name="my_image_upload" id="my_image_upload" multiple>
<input type="hidden" name="post_id" id="post_id" value="55">
<?php wp_nonce_field('my_image_upload', 'my_image_upload_nonce'); ?>
<input id="submit_my_image_upload" name="submit_my_image_upload" type="submit" value="Upload">
<h2 id="回复内容">回复内容:</h2>
<p>开发了个插件中有个上传图片的功能,插件下面有个目录是img保存图片的,想问如何课一保存上传的啊图片到这个目录?</p>
<div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false"><code>// Check that the nonce is valid, and the user can edit this post.
if (
isset($_POST['my_image_upload_nonce'], $_POST['post_id'])
&& wp_verify_nonce($_POST['my_image_upload_nonce'], 'my_image_upload')
&& current_user_can('edit_post', $_POST['post_id'])
) {
// The nonce was valid and the user has the capabilities, it is safe to continue.
// These files need to be included as dependencies when on the front end.
require_once(ABSPATH . 'wp-admin/includes/image.php');
require_once(ABSPATH . 'wp-admin/includes/file.php');
require_once(ABSPATH . 'wp-admin/includes/media.php');
// Let WordPress handle the upload.
// Remember, 'my_image_upload' is the name of our file input in our form above.
$url=WPWSL_PLUGIN_URL . '/img/' . $imageSize . '.png';
// update_option('upload_path',WP_CONTENT_DIR.'/uploads');
update_option('upload_path',WPWSL_PLUGIN_URL.'/img/');
$attachment_id = media_handle_upload('my_image_upload', $_POST['post_id']);
if (is_wp_error($attachment_id)) {
// There was an error uploading the image.
echo "<p>There was an error uploading your file.</p>";
} else {
// The image was uploaded successfully!
echo "<p>The image was uploaded successfully!</p>";
add_filter('img', $attachment_id);
// add_filter('img', 'custom_upload_directory');
}
} else {
echo "<p>The security check failed, maybe show the user an error</p>";
// The security check failed, maybe show the user an error.
}</code></pre><div class="contentsignin">Nach dem Login kopieren</div></div>
<ol><li><p>列表项目</p></li></ol>
<div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false"><code> <td>
<input type="file" name="my_image_upload" id="my_image_upload" multiple>
<input type="hidden" name="post_id" id="post_id" value="55">
<?php wp_nonce_field('my_image_upload', 'my_image_upload_nonce'); ?>
<input id="submit_my_image_upload" name="submit_my_image_upload" type="submit" value="Upload">
</td></code></pre><div class="contentsignin">Nach dem Login kopieren</div></div>
</td>

Heiße KI -Werkzeuge

Undresser.AI Undress
KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover
Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Undress AI Tool
Ausziehbilder kostenlos

Clothoff.io
KI-Kleiderentferner

AI Hentai Generator
Erstellen Sie kostenlos Ai Hentai.

Heißer Artikel

Heiße Werkzeuge

Notepad++7.3.1
Einfach zu bedienender und kostenloser Code-Editor

SublimeText3 chinesische Version
Chinesische Version, sehr einfach zu bedienen

Senden Sie Studio 13.0.1
Leistungsstarke integrierte PHP-Entwicklungsumgebung

Dreamweaver CS6
Visuelle Webentwicklungstools

SublimeText3 Mac-Version
Codebearbeitungssoftware auf Gottesniveau (SublimeText3)

Heiße Themen



PHP 8.4 bringt mehrere neue Funktionen, Sicherheitsverbesserungen und Leistungsverbesserungen mit einer beträchtlichen Menge an veralteten und entfernten Funktionen. In dieser Anleitung wird erklärt, wie Sie PHP 8.4 installieren oder auf PHP 8.4 auf Ubuntu, Debian oder deren Derivaten aktualisieren. Obwohl es möglich ist, PHP aus dem Quellcode zu kompilieren, ist die Installation aus einem APT-Repository wie unten erläutert oft schneller und sicherer, da diese Repositorys in Zukunft die neuesten Fehlerbehebungen und Sicherheitsupdates bereitstellen.

Um in cakephp4 mit Datum und Uhrzeit zu arbeiten, verwenden wir die verfügbare FrozenTime-Klasse.

Um am Datei-Upload zu arbeiten, verwenden wir den Formular-Helfer. Hier ist ein Beispiel für den Datei-Upload.

CakePHP ist ein Open-Source-Framework für PHP. Es soll die Entwicklung, Bereitstellung und Wartung von Anwendungen erheblich vereinfachen. CakePHP basiert auf einer MVC-ähnlichen Architektur, die sowohl leistungsstark als auch leicht zu verstehen ist. Modelle, Ansichten und Controller gu

Der Validator kann durch Hinzufügen der folgenden zwei Zeilen im Controller erstellt werden.

Die Anmeldung bei CakePHP ist eine sehr einfache Aufgabe. Sie müssen nur eine Funktion verwenden. Sie können Fehler, Ausnahmen, Benutzeraktivitäten und von Benutzern durchgeführte Aktionen für jeden Hintergrundprozess wie Cronjob protokollieren. Das Protokollieren von Daten in CakePHP ist einfach. Die Funktion log() wird bereitgestellt

Visual Studio Code, auch bekannt als VS Code, ist ein kostenloser Quellcode-Editor – oder eine integrierte Entwicklungsumgebung (IDE) –, die für alle gängigen Betriebssysteme verfügbar ist. Mit einer großen Sammlung von Erweiterungen für viele Programmiersprachen kann VS Code c

Dieses Kapitel befasst sich mit den Informationen zum Authentifizierungsprozess, der in CakePHP verfügbar ist.
