duanjuete9206 2018-10-26 12:44
浏览 46

Wordpress将图像上传到文件夹,Db链接甚至子类别

Hi this is what i wast to accomplish

In a folder i want a picture to be placed (testimage.jpg) and in in some custom way i want this to get link to wp_usermeta

Extra feature


that place a userid,houseid,headertext,text,Image So i seperate the image and text that different house have.

So when i have this a customer can put up there house and show picture of it. and a customer can have multiply housese thats the houseid.


This is the code to just upload an image to a folder and a referense in the db/image tabel. I have not program so mutch php. i have used like this.

add_action('the_post','test');
function test(){
$user = wp_get_current_user();
echo $user->data->ID;
}

this code i have on the test page

echo '<form action="upload.php" method="post" enctype="multipart/form-`data">';`
echo 'Select image to upload:';
echo '<input type="file" name="fileToUpload" id="fileToUpload">';
echo '<input type="submit" value="Upload Image" name="submit">';
echo '</form>';

and i have the upload.php

<?php
// Include the database configuration file
include 'dbConfig.php';
$statusMsg = '';

// File upload path
$targetDir = "uploads/";
$fileName = basename($_FILES["file"]["name"]);
$targetFilePath = $targetDir . $fileName;
$fileType = pathinfo($targetFilePath,PATHINFO_EXTENSION);

if(isset($_POST["submit"]) && !empty($_FILES["file"]["name"])){
    // Allow certain file formats
    $allowTypes = array('jpg','png','jpeg','gif','pdf','JPG','JPEG');
    if(in_array($fileType, $allowTypes)){
        // Upload file to server
        if(move_uploaded_file($_FILES["file"]["tmp_name"], `$targetFilePath)){`
            // Insert image file name into database          
            $insert = $db->query("INSERT into images (file_name, `uploaded_on) VALUES ('".$fileName."', NOW())");`



            if($insert){
                $statusMsg = "The file ".$fileName. " has been uploaded `successfully.";`
            }else{
                $statusMsg = "File upload failed, please try again.";
            } 
        }else{
            $statusMsg = "Sorry, there was an error uploading your `file.";`
        }
    }else{
        $statusMsg = 'Sorry, only JPG, JPEG, PNG, GIF, & PDF files are `allowed to upload.';`
    }
}else{
    $statusMsg = 'Please select a file to upload.';
}

// Display status message
echo $statusMsg;
?>

but i just get 404: Sidan kan inte hittas

http://wordpress.test/test/upload.php 
--the /test/ is a page and i dont know where to put the upload.php to work.

So i havent got to the place where i want to insert userid,house id to seperate them. I dont know where to put the upload.php

I have followed a guide

https://www.youtube.com/watch?v=_-uCOATMqdk

how to upload images to db
with an folder inside my wordpress.test folder.
thats called    upload_store_image_in_database_php
and in there i put a 
folder called uploads
dbconfig.php 
index.php
upload.php

when i go to

http://wordpress.test/upload_store_image_in_database_php/

when everything works, and i get a picture on the uploadfolder and a db link. But i cant adapt the code to wordpress

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 stm32开发clion时遇到的编译问题