View Full Version : FTP upload MP3 via PHP script problem

08-13-2007, 06:09 PM
I made a PHP script that allows me to upload files to FTP, I can upload images and documents with no problems, but when I go to upload an MP3, it uploads the file but has a size of 0KB on the server. I set the Max upload limit to 10MB and I'm uploading a 4MB MP3 file. Any help would be appreciated.

PHP Code:


// FTP Configuration
$FTP_User = "$username";
$FTP_Pass = "$password";
$FTP_Host = "###";
$FTP_Root = "$dir";

// If the form was submitted
if (isset($action) && $action == "submit") {

if ($_FILES['File_1']['size'] > $MAX_FILE_SIZE)
echo "Error: $Filename exceeds upload limit";

echo $_FILES['File_1']['size'];

if ($dir == "-1")
echo "Error: Please choose a File Type to upload";

// Connect to the ftp address
$Connect = ftp_connect($FTP_Host);

if (!$Connect)
echo "Error: Could not connect to ftp server<br>";

echo "Connected to $FTP_Host<br>";

// Login
$login = ftp_login($Connect, $FTP_User, $FTP_Pass);

//Turns passive mode on
$passive = ftp_pasv ($Connect, true );

echo "Current directory is now: " . ftp_pwd($Connect) . "<br>";

if (ftp_chdir($Connect, "$FTP_Root"))
echo "Current directory is now: " . ftp_pwd($Connect) . "<br>";
} else echo "Cannot change directory";

$contents = ftp_nlist($Connect, ".");

// output $contents

// check upload status
if (!passive){
echo "Failed to enter passive mode.<br>";
else {
echo "Entered passive mode.<br>";

if (!$login)
echo "Error: Could not log on as $FTP_User<br>";

echo "Logged in as $FTP_User<br>";

// Set the filename to be uploaded
$Filename = $_FILES['File_1']['name'];
$myFile = $_FILES['File_1'];

if (file_exists($Filename))
echo "The file $Filename exists<BR>";
echo "The file $Filename does not exist<BR>";

$destination_file = $FTP_ROOT.$_FILES['File_1']['name'];

// Set the local resource (the file that will be uploaded)
$file = $myFile['tmp_name'];

// If the file was successfully uploaded
$upload = ftp_put($Connect, $destination_file, $file, FTP_BINARY);

if (!$upload)
// Show success message
echo "There was a problem uploading $destination_file";
// Else show error message
echo "Successfully uploaded $Filename";



Form Code:

<title> PHP FTP Upload Test </title>
<form method="post" action="?action=submit" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="10000000">
<td><input type="text" name="username" size="30"></td>
<td><input type="password" name="password" size="30"></td>
<td>File Type:</td>
<td><select name="dir">
<option value="-1">File Type</option>
<option value="/httpdocs/charbel/upload/">Image</option>
<option value="/httpdocs/charbel/upload/">PDF</option>
<option value="/httpdocs/charbel/upload/">MP3</option>
<option value="/httpdocs/charbel/upload/">Video</option>
<td><input type="file" name="File_1" size="30"></td>
<td colspan="2" align="right"><input type="submit" value="Submit"></td>

08-13-2007, 06:47 PM
Are you sure that the server doesn't have a size limit restriction that you cannot override? You might want to check to see if this is the problem.

08-13-2007, 06:52 PM
You also may want to check with your host to see if they allow uploading of mp3 files. It's possible they could block uploading of those files.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum