PHP fastcgi模式大文件上传500错误

在linux中增加了fastcgi+php环境,结 果在文件上传时如果文件小于100KB是可以上传,但大了点就提示mod_fcgid: HTTP request length 132296 (so far) exceeds MaxRequestLen (131072)错误了,意思是fastcgi限制了文件上传大小而你要上传的文件比maxrequestlen还要大啊,所以不能上传想上传就得修改一 下配置了 查了下资料,发现fastcgi默认的请求大小为131072,于是在apache配置中添加了MaxRequestLen 配置就好了。如果你只需要修改单个虚拟主机的MaxRequestLen,原来是fastcgi模式下的设置问题,需要在配置文件.htaccess或者 直接在apache的配置文件http.conf 中指明,如下: [php] <IfModule mod_fcgid.c> AddHandler    fcgid-script .fcgi FcgidConnectTimeout  20 # to get around upload errors when uploading images increase the MaxRequestLen size to 15MB FcgidMaxRequestLen  15728640 </IfModule> [/php] 如果你是php+apache windows环境下的话我们如下配置即可 在php.ini中找到 upload_max_filesize,及其他post_max_size、max_input_time、memory_limit、 max_execution_time配置 把上传大小修改之后重启apache 即可解决。

WordPress:后台添加多个上传按钮

[php] jQuery('.upload-button').click(function() { formfield = jQuery('.upload').attr('name'); tb_show('', 'media-upload.php?type=image&amp;TB_iframe=true'); return false; }); window.send_to_editor = function(html) { imgurl = jQuery('img',html).attr('src'); jQuery('.upload').val(imgurl); tb_remove(); }; <div class="upload_field" <input type="text" name="upload_one" id="upload_one" class="upload" value="" /> <input type="button" class="upload-button" value="Upload Image" /> </div> <div class="upload_field" <input type="text" name="upload_two" id="upload_two" class="upload" value="" /> <input type="button" class="upload-button" value="Upload Image" /> </div> <div class="upload_field" <input type="text" name="upload_three" id="upload_three" class="upload" value="" /> <input type="button" class="upload-button" value="Upload Image" /> </div> [/php] 解决方法1 [php] var uploadID = ''; /*setup the var*/ jQuery('.upload-button').click(function() { uploadID = jQuery(this).prev('input'); /*grab the specific input*/ formfield = jQuery('.upload').attr('name'); tb_show('', 'media-upload.php?type=image&amp;TB_iframe=true'); return false; }); window.send_to_editor = function(html) { imgurl = jQuery('img',html).attr('src'); uploadID.val(imgurl); /*assign the value to the input*/ tb_remove(); }; [/php] 解决方法2 [php] <?php function customPostTypeUploader() { if(isset($_GET["post_type"])) { ?> <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> <script type="text/javascript"> var uploadID = ''; var storeSendToEditor = ''; var newSendToEditor = ''; jQuery(document).ready(function() { storeSendToEditor = window.send_to_editor; newSendToEditor = function(html) { imgurl = jQuery('img',html).attr('src'); $("#" + uploadID.name).val(imgurl); tb_remove(); window.send_to_editor = storeSendToEditor; }; }); function Uploader(id) { window.send_to_editor = newSendToEditor; uploadID = id; formfield = jQuery('.upload').attr('name'); tb_show('', 'media-upload.php?type=image&amp;TB_iframe=true'); return false; } </script> <?php } } add_action("admin_head", "customPostTypeUploader"); ?> <input type="text" id="image_1" name="uploaded_image_1" value="" size="40" /> <input type="button" onclick="Uploader(image_1);" title="Upload image" class="upload-button" id="add_image" value="Browse..."/> [/php]

WordPress自定义上传路径 和 生成文件的URL地址

1. options.php 中设置

直接访问:http://site_url/wp-admin/options.php,然后找到下面选项,将其设置为你所需的参数。

2. 定义 UPLOADS 常量

wp-config.php 文件中定义 UPLOADS 这个常量:
define('UPLOADS','my-uploads');
这个方法有个不好的地方:只能指定上传的相对目录,生成文件的 URL 地址不能使用子域名,这样在做静态文件 CDN 加速的时候就不是很方便。

使用 upload_dir filter

这个方法,效果其实和第一个方法基本一致:
add_filter( 'upload_dir', 'wpjam_custom_upload_dir' );
function wpjam_custom_upload_dir( $uploads ) {
	$upload_path = '';
	$upload_url_path = '';

	if ( empty( $upload_path ) || 'wp-content/uploads' == $upload_path ) {
		$uploads['basedir']  = WP_CONTENT_DIR . '/uploads';
	} elseif ( 0 !== strpos( $upload_path, ABSPATH ) ) {
		$uploads['basedir'] = path_join( ABSPATH, $upload_path );
	} else {
		$uploads['basedir'] = $upload_path;
	}

	$uploads['path'] = $uploads['basedir'].$uploads['subdir'];

	if ( $upload_url_path ) {
		$uploads['baseurl'] = $upload_url_path;
		$uploads['url'] = $uploads['baseurl'].$uploads['subdir'];
	}
	return $uploads;
}
注意修改第3、4行中$upload_path 和 $upload_url_path ,例如
$upload_path = 'img';
	$upload_url_path = 'http://img.wpdaxue.com';