开发了个插件中有个上传图片的功能,插件下面有个目录是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>
<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>
<ol><li><p>列表项目</p></li></ol>
<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>
</td>

PHP和Python各有优势,选择应基于项目需求。1.PHP适合web开发,语法简单,执行效率高。2.Python适用于数据科学和机器学习,语法简洁,库丰富。

PHP不是在消亡,而是在不断适应和进化。1)PHP从1994年起经历多次版本迭代,适应新技术趋势。2)目前广泛应用于电子商务、内容管理系统等领域。3)PHP8引入JIT编译器等功能,提升性能和现代化。4)使用OPcache和遵循PSR-12标准可优化性能和代码质量。

PHP的未来将通过适应新技术趋势和引入创新特性来实现:1)适应云计算、容器化和微服务架构,支持Docker和Kubernetes;2)引入JIT编译器和枚举类型,提升性能和数据处理效率;3)持续优化性能和推广最佳实践。

在PHP中,trait适用于需要方法复用但不适合使用继承的情况。1)trait允许在类中复用方法,避免多重继承复杂性。2)使用trait时需注意方法冲突,可通过insteadof和as关键字解决。3)应避免过度使用trait,保持其单一职责,以优化性能和提高代码可维护性。

依赖注入容器(DIC)是一种管理和提供对象依赖关系的工具,用于PHP项目中。DIC的主要好处包括:1.解耦,使组件独立,代码易维护和测试;2.灵活性,易替换或修改依赖关系;3.可测试性,方便注入mock对象进行单元测试。

SplFixedArray在PHP中是一种固定大小的数组,适用于需要高性能和低内存使用量的场景。1)它在创建时需指定大小,避免动态调整带来的开销。2)基于C语言数组,直接操作内存,访问速度快。3)适合大规模数据处理和内存敏感环境,但需谨慎使用,因其大小固定。

PHP通过$\_FILES变量处理文件上传,确保安全性的方法包括:1.检查上传错误,2.验证文件类型和大小,3.防止文件覆盖,4.移动文件到永久存储位置。

JavaScript中处理空值可以使用NullCoalescingOperator(??)和NullCoalescingAssignmentOperator(??=)。1.??返回第一个非null或非undefined的操作数。2.??=将变量赋值为右操作数的值,但前提是该变量为null或undefined。这些操作符简化了代码逻辑,提高了可读性和性能。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

ZendStudio 13.5.1 Mac
功能强大的PHP集成开发环境

Atom编辑器mac版下载
最流行的的开源编辑器

安全考试浏览器
Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。

SublimeText3 Linux新版
SublimeText3 Linux最新版

SublimeText3汉化版
中文版,非常好用