hi, my site will have been around for about a year in a few weeks, and its gone through alot of changes. it use to be just html but i've been learning PHP and i've added a few features using it. i've added a news system for the admins to post, and commenting system for users to comment on news and videos, and a few other things.
But now to the problem i'm having. I'm trying to add a page for my video editors to easily upload there videos to the /videos directory, from a page on the site. I'm still kind of new, but i've been looking searching through the forums and this is what i've come up with so far:

//here is code from ftp.php (its a .php because i'll be adding more code to it so only admins can access it..)//

<form action="ftp2.php" method="post" enctype="multipart/form-data">

<br><br>
Choose a file to upload:<br>
<input type="file" name="file"><br>
file name once on server.. don't forget to include the extension. such as .avi or .wmv<br>
<input type="text" name="name"><br>
<input type="submit" name="submit" value="submit">
</form> 


//and here is ftp2.php//

<?php
// set up the settings
$ftp_server = '***';
$ftpuser = '***';
$ftppass = '***';


$source_file = $HTTP_POST_VARS['file'];
$destination_file = '/test/'$HTTP_POST_VARS['name'];

// set up basic connection
$conn_id = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftpuser, $ftppass);

//upload the file
$upload = ftp_put($conn_id, “$destination_file”, “$source_file”, FTP_BINARY); // the ftp function

//check upload status
if (!$upload) {
		echo "Upload Failed!";
	} else {
		echo "Uploaded $source_file to $ftp_server as $destination_file";


// close the connection
ftp_close($conn_id);

?>

After i submitt a file, it goes to ftp2.php and display just a white page. I know its probly pretty obvious to one of you whats wrong, but its the best i've got.

thanks in advanced for any help

    Your quotes in the ftp_put call are wonky (literally!); you want ", not &ldquo; or &rdquo;.

    But is this videos directory on the same server as the script? If it is, then the ftp connection is unnecessary, and a [man]move_uploaded_file[/man] would achieve the desired effect. As it happens, you're not getting the file anyway; that is not in the $HTTP_POST_VARS array, but in the $HHTP_POST_FILES array. (In fact, you should be using the $_FILES array, as the older name has been deprecated).

    I'd recommend reading the Handling File Uploads section of the manual.

    If you are sending the uploads to another server, I'd recommend getting the above issues fixed (i.e., actually getting a hold of the uploaded file) and then seeing if you can ftp succesfully.

    Now for the precise nature of the catastrophe. I can see in the line

    $destination_file = '/test/'$HTTP_POST_VARS['name']; 

    that you're missing a string concatenation . between '/test/' and HTTP_POST_VARS['name']. You should have got a parse error message from this, but if display_errors has been turned off in php.ini, you won't.

      yes, its uploading to the same server. ok question. if i'm using a FTP program all my files are contained in the /httpdocs directory. is this the root? so say if i wanted to access a file on ftp it would be [url]ftp://mysite.com/httpdocs/videos/img.jpg[/url] but if i were to access it from http it would look like this http://www.mysite.com/videos/img.jpg

      this being said what would the directory be need to be set as to get it to upload to the /videos directory?

        ok i tried the following code:

        <?php 
        // Edit this 
        // Where does the file get uploaded to? 
        // put in the full path to directory with a trailing (/ on the end) slash 
        $File_path = "videos/"; 
        
        if ($_POST['Submit'] != "") { 
            // Form has been submitted. 
        
        // Set the names into shorter variables. 
        $File_name = $_FILES['TheFile']['name']; 
        $File = $_FILES['TheFile']['tmp_name']; 
        if (!(file_exists("$File_path$File_name"))) { 
            // The file doesnt exist, attempt to copy to the folder. 
            $FileCopyWorked = @copy("$File", "$File_path$File_name"); 
        } 
        if ($FileCopyWorked) { 
            echo "File has been uploaded successfully; another?<br />"; 
        } 
        else 
        { 
            echo "File has not been uploaded successfully; Please make sure the directory exists, try again?<br />"; 
        } 
        } 
        // Gets current file name. 
        $Current_Page = basename($_SERVER['PHP_SELF']); 
        
        // Displays the form 
        echo '<form method="post" action="' . $Current_Page . '" enctype="multipart/form-data"> 
        <input name="TheFile" type="file" style="width:100%;"><br /> 
        <input type="submit" name="Submit" style="width:100%;"><br /> 
        </form>'; 
        ?> 

        but i keep getting the "File has not been uploaded successfully; Please make sure the directory exists, try again?" error. and i'm pretty sure it's because of $File_path. like i said in my last post should $File_path = "videos/"; ? or something else?

          silly question...but

          Did you check permissions on the videos directory to make sure the ftp user had write access?

            the user i'm using has universal access. it has the power to add/remove/edit anything and everything.
            and if i totaly took what you said the wrong way. if it helps, i know i can upload things into it using an ftp program...

              another shot in the dark, do you get an warning message when you remove the @ sign from copy?

              Change this line from:

              $FileCopyWorked = @copy("$File", "$File_path$File_name");

              to:

              $FileCopyWorked = copy("$File", "$File_path$File_name");

                yep after taking out the @, i still get the warning message when the directory is set to "videos/"

                  Write a Reply...