嗨,这就是我要完成的事情
在文件夹中我要放置图片(testimage.jpg) 并且以某种自定义方式,我希望它能够链接到wp_usermeta
其他功能
放置用户ID,房屋ID,标题文本,文本,图像的
所以我将不同房子的图像和文本分开。
因此,当我有这个东西时,客户可以在那儿放房子并显示图片。 并且客户可以拥有多个房屋,即房屋编号。
这是仅将图像上载到db / image表格中的文件夹和引用的代码。 我没有编程,所以mutch php。 我曾经这样用过。
add_action('the_post','test');
function test(){
$user = wp_get_current_user();
echo $user->data->ID;
}
我在测试页上有此代码
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>';
我有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;
?>
但是我刚得到 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.
所以我还没有到达要插入用户ID和房屋ID的地方。我不知道将upload.php放在哪里
我遵循了指南
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
我去
http://wordpress.test/upload_store_image_in_database_php/
当一切正常时,我在uploadfolder和db链接上得到了一张图片。但是我无法使代码适应wordpress