我正在尝试调整图像大小并将路径保存到我的数据库中,我也想将其移动到地图上。一切正常,除了移动到目录。我也知道我需要使用MySQL或PDO而不是MySQL,但这只是一个例子。 有谁知道为什么?
这是我的代码:
//Database connection made
error_reporting(0);
$change="";
$abc="";
define("MAX_SIZE","400");
function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
$errors=0;
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$image=$_FILES['file']['name'];
$uploadedfile=$_FILES['file'];
if ($image)
{
$filename = stripslashes($_FILES['file']['name']);
$extension= getExtension($filename);
$extension =strtolower($extension);
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension !="gif"))
{
echo 'Onbekende image extensie';
$errors=1;
}
else
{
$size=filesize($_FILES['file']['tmp_name']);
if ($size > MAX_SIZE*9999999999)
{
echo "Je hebt het size limit overschreden";
$errors=1;
}
if($extension=="jpg" || $extension=="jpeg")
{
$uploadedfile = $_FILES['file']['tmp_name'];
$src = imagecreatefromjpeg($uploadedfile);
}
else if ($extension=="png")
{
$uploadedfile = $_FILES['file']['tmp_name'];
$src = imagecreatefromgif($uploadedfile);
}
else
{
$src=imagecreatefromgif($uploadedfile);
}
list($width,$height)=getimagesize($uploadedfile);
$newwidth=240;
$newheight=($height/$width)*$newwidth;
$tmp=imagecreatetruecolor($newwidth,$newheight);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
$filename = $_FILES['file']['name'];
imagejpeg($tmp,$filename,100);
imagedestroy($src);
imagedestroy($tmp);
}
}
}
if (isset($_FILES['file']['name'])){
$filename = $_FILES['file']['name'];
$folder="uploads/";
move_uploaded_file($filename,$folder.$filename);
$handle = $folder.$filename;
}
//database connection closed + file pad saved to database
该文件正在“上传”地图上方的地图中上传。 现在文件保存在'root /'中,但它应该是'root / uploads /'。
有人可以解决我的move_uploaded_file
问题吗?
答案 0 :(得分:0)
试试这个
$filename = $_FILES['file']['name'];
$folder="uploads/".$filename;
move_uploaded_file($_FILES['file']['tmp_name'],$folder);