PHP   发布时间:2022-04-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了PHP图像上传(WordPress自定义插件)大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

我有一个正在使用的wordpress插件,似乎遇到了问题.
我需要用户能够上传图片,但我一直遇到这个问题

上载目录不可写或不存在.

该目录绝对存在,我什至将CHMOD更改为777进行测试.

products.PHP文件如下所示:

 <?
if ('POST' == $_SERVER['requEST_METHOD'])
 {
global $wpdb;

$product_title = $_POST['title'];
$product_url = $_POST['url'];
$producT_Btn_text = $_POST['btn_text'];

// CREATE UNIQUE NAME FOR IMAGE
$remote_addr = $_SERVER['REMOTE_ADDR'];
$time = time();
$new_name = $remote_addr;
$new_name .= $time;


// IMAGE UPLOAD

$upload_dir = "http://markpetherbridge.co.uk/ios/wp-content/plugins/rap/includes/productimages/"; 

if (file_exists($upload_dir) && is_writable($upload_dir)) {
        echo "<br /> Directory exists and is fine.... <br />";
}
else {
        echo "Upload directory is not writable, or does not exist. <br />";
}

$uploadedfile = $_FILES['image_file']['name'];
$extension = explode(".", $uploadedfilE);
$extensiontype = $extension['1'];

$target_path = $upload_dir;
$target_path = $target_path .$new_name .'.'.$extensiontype; 

if(move_uploaded_file($_FILES['image_file']['tmp_name'], $target_path)) {
        echo "The file ".  basename( $_FILES['image_file']['name']). 
        " has been uploaded <br />";
} else{
    echo "There was an error uploading the file, please try again! <br />";

}

$product_img = $new_name.'.'.$extensiontype;

//ADD TO DATABASE
    $wpdb->query("INSERT INTO wp_rec_amazon_product (product_title, product_url,    product_img, producT_Btn_text) VALUES ('$product_title', '$product_url','$product_img','$producT_Btn_text')");
echo "You have successfully added "  .$product_title.   " to your products list";

} else { ?>

 <form action="<?PHP $_SERVER['PHP_SELF']; ?>" method="POST" enctype="multipart/form-data">
<table border="0" bordercolor="none" width="50%" cel@R_944_10697@ding="0" cellspacing="0">
    <tr>
        <td>Product title:</td>
        <td><input type="text" name="title" value="product title" /></td>
    </tr>
    <tr>
        <td>Product Url</td>
        <td><input type="text" name="url" value="product url" /></td>
    </tr>
    <tr>
        <td>Button text</td>
        <td><input type="text" name="btn_text" value="Get your copy" /></td>
    </tr>

</table>
    <input type="file" name="image_file" />



    <input type="submit" value="Submit" />
</form>

 <?PHP }?>

信息被添加数据库中,只是图像上传似乎不起作用.

有人知道吗?谢谢大家.

大佬总结

以上是大佬教程为你收集整理的PHP图像上传(WordPress自定义插件)全部内容,希望文章能够帮你解决PHP图像上传(WordPress自定义插件)所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: