I would like to upload the image from the form on the front page using PHP and HTML on Wordpress, and display the image on the confirmation screen on the fixed page after POST transmission.
Using the following site as a reference, I wrote php on the page after the transition, but the upload failed.
I think the relative path in Wordpress is incorrect, but I don't know how to write it.
The error is
Warning: move_uploaded_le (./img/20210217_1728.png): failed to open stream:
No such or directory in ~ /~ /page.php.online58
will be
Upload image file 1 (HTML+PHP only)
$up_file="img/".date("Ymd_His.").mt_land(1000,9999).".$ext";
"img/"
portion of the
I would appreciate it if you could let me know if anyone understands.
<!DOCTYPE html>
<html lang="ja">
<head>
<metacharset="UTF-8">
<title>File Submission Page 1</title>
</head>
<body>
<form method="post" enctype="multipart/form-data" action="file1.php">
<input type="file" name="up">
<input type="submit" value="upload">
</form>
</body>
</html>
<?php
$up_file="";
$up_ok = false;
$tmp_file=isset($_FILES["up"]["tmp_name"])? $_FILES["up"]["tmp_name"]:";
$org_file=isset($_FILES["up"]["name"])? $_FILES["up"]["name"]:";
if($tmp_file!="&&
is_uploaded_file($tmp_file)
{
$split=explode('.',$org_file); $ext=end($split);
if($ext!=""&&
$ext!=$org_file)
{
$up_file="img/".date("Ymd_His.").mt_land(1000,9999)..".$ext";
$up_ok = move_uploaded_file($tmp_file,$up_file);
}
}
?>
<!DOCTYPE html>
<html lang="ja">
<head>
<metacharset="UTF-8">
<title>File Receive Page 1</title>
</head>
<body>
<p><?php if($up_ok){?>
The uploaded file is <img src="<?=$up_file?>">.
<?php}else{?>
Upload failed.
<?php}?>/p>
<a href="file1.html">Back to Upload Page</a>
</body>
</html>
Questioner only
php wordpress image form
Problem solved.I didn't know how to write the relative path.
$up_file="img/"
instead
$up_file="./img"
and
The function works and
in the hierarchy above the img folder.
You can now put photo files everywhere.
© 2024 OneMinuteCode. All rights reserved.