我制作了一个脚本,通过php和foto从表单上传到FTP服务器。。。但这不是工作,当我使用$_FILES['userfile']['error'
]函数是给我返回VALUE 1,意思是UPLOAD_ERR_INI_SIZE
值:1;上载的文件超过了php.ini中的upload_max_filesize
指令。但我和主机公司的人谈过,他们说最大尺寸是100mb,我试着上传一张只有30kb的图片,他们也试着用cPanel上传,结果。。。
表单代码
<form action="foto-test.php" enctype="multipart/form-data" method="post">
<input name="file" type="file" />
<input name="submit" type="submit" value="Upload File" />
</form>
fo-to-test.php
<?php
$ftp_server = "ftp.xxxx.com";
$ftp_user_name = "xxx@xxx.com";
$ftp_user_pass = "xxxx";
$destination_file = "/public_html/images/" . $_FILES['file']['name'];
$source_file = $_FILE['file']['tmp_name'];
// set up basic connection
$conn_id = ftp_connect($ftp_server);
ftp_pasv($conn_id, true);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// check connection
if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed!";
echo "Attempted to connect to $ftp_server for user $ftp_user_name";
exit;
} else {
echo "Connected to $ftp_server, for user $ftp_user_name";
}
// upload the file
if ($_FILES['file']['error'] != UPLOAD_ERR_OK) {
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);
echo "Uploaded $source_file to $ftp_server as $destination_file";
}
else { echo !$upload;
}
// check upload status
if (!$upload) {
echo " FTP upload has failed!";
} else {
echo "Uploaded $source_file to $ftp_server as $destination_file";
}
// close the FTP stream
ftp_close($conn_id);
?>
当我尝试上传图像时,消息是
已连接到xxx,对于用户xxx1FTP上载已失败!因此1表示UPLOAD_ERR_INI_SIZE值:1;上载的文件超过upload_max_filesize指令在php.ini中。但我有100毫巴的酸橙。。。那么怎么了?
编辑://TOPIC CLOSED,我解决了这个问题,我不得不在ftp_put
语句
FTP_ASCII
修改FTP_BINARY
上传代码ftp_put()、ftp_BINARY似乎有问题,与php.ini或上传大小无关,这是最终代码。
<?php
$ftp_server = "ftp.xxxx.com";
$ftp_user_name = "ftpusername";
$ftp_user_pass = "ftppass";
$destination_file = "/public_html/" . $_FILES['file']['name'];
$source_file = $_FILES['file']['tmp_name'];
// set up basic connection
$conn_id = ftp_connect($ftp_server);
ftp_pasv($conn_id, true);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// check connection
if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed!";
echo "Attempted to connect to $ftp_server for user $ftp_user_name";
exit;
} else {
echo "Connected to $ftp_server, for user $ftp_user_name";
}
// upload the file
if (ftp_put($conn_id, $destination_file, $source_file, FTP_ASCII)) {
echo "successfully uploaded $destination_file'n";
} else {
echo "There was a problem while uploading $destination_file'n";
}
// close the FTP stream
ftp_close($conn_id);
?>
可能是他们这边出了故障。文件清楚地表明,限制由定义
upload_max_filesize-已上载文件的最大大小。
如果您确定您的POST_MAX_SIZE小于UPLOAD_MAX_FILESIZE,请联系他们并告诉他们仔细检查,看看它是否真的是MB而不是B。