【问题标题】:File not uploading and moving to folder文件未上传并移动到文件夹
【发布时间】:2014-04-30 22:50:24
【问题描述】:
$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.";
 }

由于某种原因,“else”不断出现(上传文件时出现问题)。我把 cmets 放在我想做的所有事情中。请帮忙!谢谢!

【问题讨论】:

  • 您是否首先确认文件正在上传?
  • 您确定您的服务器对您尝试移动文件的目录具有写入权限吗?
  • session_start(); 加载了吗?如果不是,那么这就是您的代码失败的原因之一。
  • var_dump($id); 或 var_dump($_SESSION['id']); 以及 var_dump($target); 给你什么? @user3370114 将 var_dump($target); 放在 $target = $target . $id.".".$ext; 之后
  • 非常感谢您今晚的帮助。我很高兴知道世界上还有好人

标签: php if-statement file-upload


【解决方案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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-26
    • 2016-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多