我制作了一个脚本,通过php从一个表格上传图片到ftp服务器...但是没有用,当我使用$_FILES['userfile']['error'
]函数返回值VALUE 1意味着UPLOAD_ERR_INI_SIZE
值:1; 上传的文件超出了upload_max_filesize
php.ini中的指令。但是我与托管公司的人员交谈,他们说最大大小为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>
foto-test.php
<?php
$ftp_server = "ftp.xxxx.com";
$ftp_user_name = "[email protected]";
$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,用户xxx 1 FTP上传失败!因此1表示UPLOAD_ERR_INI_SIZE值:1;上传的文件超过了php.ini中的upload_max_filesize指令。但是我的石灰是100 mb。。。那怎么了??
编辑://主题关闭,我解决了问题,我不得不modificied将FTP_BINARY
与FTP_ASCII
在ftp_put
声明
似乎上传代码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);
?>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句