Forum Moderators: coopster

Message Too Old, No Replies

Php Upload File

...hard day...

         

omoutop

2:43 pm on Jul 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi to all,

I am encountering some difficulties uploading a file into a specific path of my server using ftp in php...
I have changes my code several times to make it work but it doesnt and I cant find the reason...
I have changes the attributes of the target folder to 777 but still nothing...

the message I get according to my code is :

Connected to xx.xx.xx.xx, for user user@mysite,com...
FTP upload has failed!

this is a part of my code....

if ($_REQUEST['action'] == "add")
{
////first selecting all area details
$select_area = "select * from areas WHERE area_id = '".$_REQUEST['area_id']."'";
$run_area = mysql_query($select_area) or die (mysql_error());
$row_area = mysql_fetch_assoc($run_area);
///now to declare and check file
$userfile1 = $HTTP_POST_FILES['file1']['tmp_name'];
$userfile_name1 = $HTTP_POST_FILES['file1']['name'];
$userfile_size1 = $HTTP_POST_FILES['file1']['size'];
$userfile_type1 = $HTTP_POST_FILES['file1']['type'];
$userfile_error1 = $HTTP_POST_FILES['file1']['error'];
///time to check file
if ($userfile_error1 > 0)
{
// echo 'Problem: ';
switch ($userfile_error1)
{
case 1: echo 'file size limit reached(25kb)<a href="javascript:history.back(1);"><strong>Προηγούμενη σελίδα</strong></a>'; break;
case 2: echo 'Η size limit reached(25kb) <a href="javascript:history.back(1);"><strong>Προηγούμενη σελίδα</strong></a>'; break;
case 3: echo 'a problem has been encountered, banner is not uploaded <a href="javascript:history.back(1);"><strong>Προηγούμενη σελίδα</strong></a>'; break;
case 4: echo 'a problem has been encountered, banner is not uploaded <a href="javascript:history.back(1);"><strong>Προηγούμενη σελίδα</strong></a>'; break;
}
exit;
}
else
{
//time to upload
$usernm = explode("www.",$row_area['url']);
$usernm = $usernm[1];
// set up basic connection
$ftp_server = $row_area['ip']; //set ip
$conn_id = ftp_connect($ftp_server); //connecting
$ftp_user_name = $row_area['username']."@".$usernm; //set username
$ftp_user_pass = $row_area['password']; //set password
$source_file = $userfile_name1;
echo $source_file;
$destination_file = "banners/".$userfile_name1;
echo "<br>";
echo $destination_file;
echo "<br>";
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
if ((!$conn_id) ¦¦ (!$login_result)) {
echo "FTP connection has failed!Attempted to connect to $ftp_server for user $ftp_user_name.<br>";
exit;
} else {
echo "Connected to $ftp_server, for user $ftp_user_name...<br> ";
}
// upload the file
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);
// check upload status
if (!$upload) {
echo "FTP upload has failed! ";
} else {
echo "Uploaded $source_file to $ftp_server as $destination_file. ";
/////////////////time to update DATABASE
$insert = "INSERT INTO static_banners (area_id, banner_alt, banner, banner_position,
link, banner_type) VALUES ('".$_REQUEST['area_id']."', '".$_POST['banner_alt']."',
'".$userfile_name1."', '".$_REQUEST['banner_position']."', '".$_POST['link']."',
'".$_POST['banner_type']."')";
$run_insert = mysql_query($insert) or die (mysql_error());
if ($run_insert)
{
$msg .= "done, please wait.... ";
?>
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
window.opener.location.href="manage-banners.php?area_id=<? echo $_REQUEST['area_id'];?>";
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript"> setTimeout('self.close()',500); </SCRIPT>
<?
}
else
{
$msg .= "a problem has been encountered. ";
}
}
// close the FTP stream
ftp_close($conn_id);
}
}
################################################################

Can you see any problem? Any thoughts are appreciated!
Thanks in advance

omoutop

3:00 pm on Jul 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Solved by changing the following 2 lines:

$source_file = $userfile1;
$destination_file = "public_html/banners/".$userfile_name1;

Great!