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