Stefan J. Stefan J. - 4 months ago 20
PHP Question

Error UPLOAD_ERR_INI_SIZE Value: 1; when try to upload a image using php to FTP

I made a script to upload from a form via php a foto to the FTP servers... but isnt work, when i used

$_FILES['userfile']['error'
] function
is return me the VALUE 1 which means
UPLOAD_ERR_INI_SIZE

Value: 1; The uploaded file exceeds the
upload_max_filesize
directive in php.ini.
but i spoke with the guys from the host company and they said is a max size fro 100mb, and i tried to uploade a image which has only 30kb, and also they tried to uploade using cPanel and its worked...

form code

<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 = "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);
?>


the the message when i try to upload a image is

Connected to xxx, for user xxx 1 FTP upload has
failed!
so the 1 means UPLOAD_ERR_INI_SIZE
Value: 1; The uploaded file exceeds the upload_max_filesize directive
in php.ini.
but i have a lime fro 100 mb... so what is wrong? ?

EDIT:// TOPIC CLOSED, I fixed the problem, i had to modificied the
FTP_BINARY
with
FTP_ASCII
in the
ftp_put
statement

Answer

It seems there is a problem with the upload code ftp_put(), FTP_BINARY and nothing to do with the php.ini OR upload size, here is final code.

<?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);
?>