SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Dec 2003
    Location
    Midlands, UK
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy PHP/FTP problems

    I've tried to create this upload script in PHP using an FTP server (Serv-U)

    The problem I have is that only I can seem to upload to it (the person hosting both the site and the FTP server).

    They can connect to the site fine, but the upload bit: ftp_put doesnt seem to work for them.

    Here is the script:

    Code:
    <?
    											 
     if (isset($_POST["txt_file"]))
    			{
    		//echo "hi";
    		global $place; 
    		$place = $_POST["sel_place"];
    		// echo $place;
    		$file = $_POST["txt_file"];
    		$itemArray = explode("\\", $file);
    		$filename = $itemArray[sizeof($itemArray)-1];
    		 //echo '<b>' . $filename . '</b>';
    		$ftp   = 'ftp://reddwarf/';
    function doconn($place) 
    { 
    global $ftpServer; 
    global $ftpUser; 
    global $ftpPass;
    global $c;
    global $l;
    $ftpServer = "reddwarf";
    if ($place == "forum")
    {
    $ftpUser = "userimages";
    $ftpPass = "userimages";
    }
    if ($place == "file")
    {
    $ftpUser = "uploading";
    $ftpPass = "uploading";
    }
    $c = @ftp_connect($ftpServer); 
    $l = @ftp_login($c, $ftpUser, $ftpPass); 
    
    if(!$c) 
    die("A connection to $ftpServer couldn't be established"); 
    else if(!$l) 
    die("Your login credentials were rejected"); 
    else 
    return $c; 
    } 
    
    						$conn = doconn($place); 
    
    	
    						//echo "HI";				 
    								
    								if ((!$c) || (!$l))
    								{
    					echo "FTP Connection has failed!";
    					echo "Attempted to connect to $ftp for $ftpUser";
    					exit;
    								}
    								else
    								{
    					//echo "Connected to $ftp, for user $ftpUser";
    								}
    					$upload = ftp_put($c, $filename, $file, FTP_ASCII);
    								
    					if (!$upload)
    								{
    					echo "FTP upload has failed!";
    								}
    					else
    								{
    					echo "<font size = '4' color = 'red'>Upload $filename to $ftp was successful</font>";
    								}
    								ftp_close($conn);
    }
    ?>
    				<form action="" method = "POST">
    				 <table cellpadding = "0" cellspacing = "0" border = "2" bordercolor = "#3377aa" width = "100%">
    				<tr><td><table bgcolor = "#eeeeee" width = "100%"><tr><td>
    				 Upload a file here for use in either the forums or the files section:<br>
    				<font color = "red" size = "1"><b>Please Note that if you are uploading files greater than 10mbs it will take some time
    				so just leave the browser open</b></font> <br><br>
    				Place: <br>
    				 <SELECT NAME="sel_place">
    				<option checked value="forum">Forum Image</option>
    				 <option value="file">File Section</option>
    				</SELECT><br>
    				File: <br>
    				<INPUT TYPE="file" NAME="txt_file" SIZE=35 MAXLENGTH=50><br>
    				<input type = "submit" value = "Upload"><br><br><br>
    				<font color = "blue" size = "1">**If you get an error then there maybe a file there with the same name,
     try renaming the file you are trying to upload</b></font><br>
    			</td></tr></table>				</td></tr></table></form><br>
    Many thanks for your help,

    -Dougie

  2. #2
    PHP manual bot bronze trophy Gaheris's Avatar
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,195
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You say 'them', does it work for you? Do you get any error messages? What exactly doesn't work?

  3. #3
    SitePoint Member
    Join Date
    Dec 2003
    Location
    Midlands, UK
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Gaheris
    You say 'them', does it work for you? Do you get any error messages? What exactly doesn't work?
    It works for me.

    But not for other people accessing the site (I am running it on an intranet atm), they get the error:

    "FTP upload has failed!"

    the download system I have works, which means the logining on its fine, it just doesnt seem to like the FTP_PUT bit..... I'm guessing I need to add or take away soemthing from one of the variables???

    Thanks,

    -Dougie

  4. #4
    SitePoint Member
    Join Date
    Dec 2003
    Location
    Midlands, UK
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No one know



  5. #5
    SitePoint Member
    Join Date
    Dec 2003
    Location
    Midlands, UK
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Final Bump

    I really need to get this working.... I've tried everything.

    Thanks,

    -Dougie

  6. #6
    PHP manual bot bronze trophy Gaheris's Avatar
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,195
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does the script have access to the file specified in the $file variable?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •