你好,SE的了不起的人!:)
好吧,这有点牵强,但我正在尝试获得一个带有PHP上载脚本的HTML表单,以便在Wordpress页面中工作。我不能使用插件。它应该是一个类似设计团队的网页,客户可以通过html表单上传图像(需要登录和其他东西,但我稍后会处理)
我有一个子主题,我创建了一个名为“upload”的页面,我正在编辑文件“page upload.php”
My form in page-upload.php
<form action="<?php bloginfo(\'template_url\'); ?>/upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="file" />
<input type="submit" name="submit" value="Upload" />
</form>
form action=“upload.php”没有正确定位文件,所以在google搜索后,我发现:
<?php博客信息(\'template\\u url\');?>/上载php“
它可以定位文件,但不是上载图像,而是回显PHP中的每个回显。
我已经使用了W3Schools PHP文件上传示例来开始,但obv并不像我希望的那么简单^_^
http://www.w3schools.com/php/php_file_upload.asp
<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
?>
那么,这是否可以在WP中通过PHP和HTML实现,或者需要一些JS\\jQuery