dou91855 2014-04-30 22:50
浏览 38

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

$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.";
 }

for some reason the "else" keeps showing up (there was a problem uploading the file). I put comments in everything that I am trying to do. please help! thanks!

  • 写回答

1条回答 默认 最新

  • doumi1311 2014-05-01 23:35
    关注

    To close the question as per OP's request.

    The issue is that you need to increase the maximum size for uploads. PHP's default is usually 2M and you are most probably trying to upload a file larger than what the maximum setting is set to.

    This can be achieved in two ways.

    By editing your php.ini file with the following settings:

    ; Maximum allowed size for uploaded files.
    upload_max_filesize = 40M
    
    ; Must be greater than or equal to upload_max_filesize
    post_max_size = 40M
    

    or via an .htaccess file placed in the root of your server:

    php_value upload_max_filesize 20M
    php_value post_max_size 30M
    
    评论

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题