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">Salin selepas log masuk</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">Salin selepas log masuk</div></div>
</td>

Alat AI Hot

Undresser.AI Undress
Apl berkuasa AI untuk mencipta foto bogel yang realistik

AI Clothes Remover
Alat AI dalam talian untuk mengeluarkan pakaian daripada foto.

Undress AI Tool
Gambar buka pakaian secara percuma

Clothoff.io
Penyingkiran pakaian AI

AI Hentai Generator
Menjana ai hentai secara percuma.

Artikel Panas

Alat panas

Notepad++7.3.1
Editor kod yang mudah digunakan dan percuma

SublimeText3 versi Cina
Versi Cina, sangat mudah digunakan

Hantar Studio 13.0.1
Persekitaran pembangunan bersepadu PHP yang berkuasa

Dreamweaver CS6
Alat pembangunan web visual

SublimeText3 versi Mac
Perisian penyuntingan kod peringkat Tuhan (SublimeText3)

Topik panas



PHP 8.4 membawa beberapa ciri baharu, peningkatan keselamatan dan peningkatan prestasi dengan jumlah penamatan dan penyingkiran ciri yang sihat. Panduan ini menerangkan cara memasang PHP 8.4 atau naik taraf kepada PHP 8.4 pada Ubuntu, Debian, atau terbitan mereka

Untuk bekerja dengan tarikh dan masa dalam cakephp4, kami akan menggunakan kelas FrozenTime yang tersedia.

Untuk mengusahakan muat naik fail, kami akan menggunakan pembantu borang. Di sini, adalah contoh untuk muat naik fail.

CakePHP ialah rangka kerja sumber terbuka untuk PHP. Ia bertujuan untuk menjadikan pembangunan, penggunaan dan penyelenggaraan aplikasi lebih mudah. CakePHP adalah berdasarkan seni bina seperti MVC yang berkuasa dan mudah difahami. Model, Pandangan dan Pengawal gu

Pengesah boleh dibuat dengan menambah dua baris berikut dalam pengawal.

Log masuk CakePHP adalah tugas yang sangat mudah. Anda hanya perlu menggunakan satu fungsi. Anda boleh log ralat, pengecualian, aktiviti pengguna, tindakan yang diambil oleh pengguna, untuk sebarang proses latar belakang seperti cronjob. Mengelog data dalam CakePHP adalah mudah. Fungsi log() disediakan

Kod Visual Studio, juga dikenali sebagai Kod VS, ialah editor kod sumber percuma — atau persekitaran pembangunan bersepadu (IDE) — tersedia untuk semua sistem pengendalian utama. Dengan koleksi sambungan yang besar untuk banyak bahasa pengaturcaraan, Kod VS boleh menjadi c

Bab ini membincangkan maklumat tentang proses pengesahan yang terdapat dalam CakePHP.
