我正在尝试在自定义word-press模板中编写上传图片代码。它在php中工作。当我在word-press模板上移动它时,它会显示警告并停止执行脚本。这是我的代码。假设所有表和文件夹都是使用适当的权限777创建的。
<?php
require('../../../wp-load.php');
require('../../../wp-config.php');
function GetImageExtension($imagetype)
{
if(empty($imagetype)) return false;
switch($imagetype)
{
case 'image/bmp': return '.bmp';
case 'image/gif': return '.gif';
case 'image/jpeg': return '.jpg';
case 'image/png': return '.png';
default: return false;
}
}
if (!empty($_FILES["uploadedimage"]["name"])) {
$file_name=$_FILES["uploadedimage"]["name"];
$temp_name=bloginfo('template_directory').$_FILES["uploadedimage"]["tmp_name"];
$imgtype=$_FILES["uploadedimage"]["type"];
$ext= GetImageExtension($imgtype);
$imagename=date("d-m-Y")."-".time().$ext;
$tmp=bloginfo('template_directory');
$remain = "/images/".$imagename;
$target_path = $tmp.$remain;
if(move_uploaded_file($temp_name, $target_path)) {
$query_upload="INSERT into images_tbl (images_path) VALUES ('$target_path')";
mysql_query($query_upload) or die(mysql_error());
}else{
exit("Error While uploading image on the server");
}
}
&GT;
输出:
Warning: move_uploaded_file(/images/16-12-2014-1418709361.gif) [function.move-uploaded-file]: failed to open stream: No such file or directory in /opt/lampp/htdocs/wordpress2/wp-content/themes/twentythirteen/saveimage.php on line 31
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpuS9XNY' to '/images/16-12-2014-1418709361.gif' in /opt/lampp/htdocs/wordpress2/wp-content/themes/twentythirteen/saveimage.php on line 31
Error While uploading image on the server
答案 0 :(得分:0)
Please you try this
One more thing you remember when we move file need 2 parameter
a file name
b path of the folder which one you want move your picture.
ex : $destination = "test/". $name;// this is path
$answer = move_uploaded_file($_FILES['user_file']['tmp_name'],$destination);