文件无法上传和移动到文件夹

时间:2014-04-30 22:50:24

标签: php if-statement file-upload

$image = $_FILES['picture']['name'];
$id=$_SESSION['id'];
//This function separates the extension from the rest of the file name and returns it 
 function findexts ($filename) 
 { 
 $filename = strtolower($filename) ; 
 $exts = split("[/\\.]", $filename) ; 
 $n = count($exts)-1; 
 $exts = $exts[$n]; 
 return $exts; 
 }  

 $ext = findexts ($_FILES['picture']['name']) ; 
 //This assigns the subdirectory you want to save into... make sure it exists!
 $target = "mainimage/";
 //This combines the directory, the random file name, and the extension
 $target = $target . $id.".".$ext; 
 if(move_uploaded_file($_FILES['picture']['tmp_name'], $target)) 
 {
 echo ("This is your new profile picture!");
 } 
 else
 {
 echo "Sorry, there was a problem uploading your file.";
 }

出于某种原因"否则"不断出现(上传文件时出现问题)。我把评论放在我想要做的每件事上。请帮忙!谢谢!

1 个答案:

答案 0 :(得分:1)

按照OP的要求关闭问题。

问题是您需要增加上传的最大尺寸。 PHP的默认值通常为2M,您很可能尝试上传的文件大于设置的最大设置值。

这可以通过两种方式实现。

使用以下设置编辑php.ini文件:

; Maximum allowed size for uploaded files.
upload_max_filesize = 40M

; Must be greater than or equal to upload_max_filesize
post_max_size = 40M

或通过放置在服务器根目录中的.htaccess文件:

php_value upload_max_filesize 20M
php_value post_max_size 30M