14 Replies - 2205 Views - Last Post: 19 May 2012 - 04:25 AM Rate Topic: -----

#1 TechnoBear  Icon User is offline

  • D.I.C Head

Reputation: 18
  • View blog
  • Posts: 222
  • Joined: 02-November 11

PHP FTP MP3 Upload

Posted 03 May 2012 - 09:21 AM

I have with a little help from tutorials (I haven't done anything with PHP before starting this job) managed to put together an upload script (see below) however every time i try to upload an MP3 it fails. I work for a radio station and we need to be able to allow hosts to upload their music to the website so we anyone with clearance can access it.

Current Upload code:

Index.html form:
<p>Select File for Upload (1GB Max transfer)</p>
<form action="upload.php" method=POST enctype="multipart/form-data" name="form1" >
<p>Select File for Upload</p>
<input type="file" name="source_file" size="40">
<br />
<input type="submit" name="Submit" value="Upload">
</form>



Upload.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
	<title>WAZU | Staff DropBox</title>
	
	<link rel="stylesheet" type="text/css" href="/CSS.css" />
	<script type="text/javascript" src="/openwindow.js"></script>
	<script type="text/javascript" src="/showhide.js"></script>
	<script type="text/javascript" src="/menu.js"></script>
	<script type="text/javascript" src="/rand.js"></script>
</head>
<body class="main">
<div id="background">
    <img src="/images/background.jpg" class="stretch" alt="" />
</div>
<script type="text/javascript" src="/header.js"></script>
<table width="1150px">
<tr>
<td />
<td align="center">
<h2>Upload Files</h2>
</td>
</tr>
<tr>
<td width="210px" />
<td>
<?php
       
    $ftp_server='*IP*';
    $conn_id = ftp_connect($ftp_server);
   
  
    // login with username and password
    $user="*username*";
    $passwd="*Pass*";
    $login_result = ftp_login($conn_id, $user, $passwd);

// check connection
   if ((!$conn_id) || (!$login_result)) {
        echo "FTP connection has failed!";
        echo "Attempted to connect to $ftp_server for user $ftp_user_name";
        die;
    } else {
        echo "<br>Connected to $ftp_server, for user $user<br>";
    }
//directory
  ftp_chdir($conn_id, "www.wazufm.org");
  ftp_chdir($conn_id, "upload");

//$destination_file=ftp_pwd($conn_id);

$destination_file=basename($_FILES['source_file']['name']);
echo ("<br>");
print $destination_file;
echo("<br>");
print $source_file;
echo("<br>");
print $_source_file;
echo ("<br>");

// upload the file
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_ASCII);

// 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);
?>
</td>
<td align="right" class="fsrn">
<noscript>
<p><a href="http://fsrn.org/newscast">Get FSRN News</a></p>
</noscript>
<script type="text/javascript" id="fsrnnews" src="http://output10.rssinclude.com/output? type=js&id=108949&hash=42756d58ef0ba7840912fc3398b15d4d"></script>
</td>
</tr>
<tr>
<td />
<td align="center">
<iframe src="ftp://*username*:*Pass*@web1001.opentransfer.com" id="programlist" name="ftplist" title="ftplist" />
</td>
</tr>
<tr>
<td />
<td align="center">
<img src="../images/pacifica-logo.jpg" />
</td>
</tr>
<tr>
<td />
<td  align="center">
<h5>Copyright©2011 WAZU 90.7 FM</h5>
</td>
</tr>
</table>
</body>
</html>


username, password and ip obscured for obvious reasons.

This code works fine for uploading anything that isn't an audio file. I have attempted to change settings in php.ini to no avail.

Is This A Good Question/Topic? 0
  • +

Replies To: PHP FTP MP3 Upload

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6036
  • View blog
  • Posts: 23,432
  • Joined: 23-August 08

Re: PHP FTP MP3 Upload

Posted 03 May 2012 - 10:12 AM

It would be helpful to know HOW it fails. Errors, whatever.
Was This Post Helpful? 0
  • +
  • -

#3 TechnoBear  Icon User is offline

  • D.I.C Head

Reputation: 18
  • View blog
  • Posts: 222
  • Joined: 02-November 11

Re: PHP FTP MP3 Upload

Posted 03 May 2012 - 10:17 AM

well all from running tests and checking them against the code is that it accepts the input from the form as $destination_file gets populated however $source_file does not print out so it cannot be creating a tmp file.

It works fine on image files etc.
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6036
  • View blog
  • Posts: 23,432
  • Joined: 23-August 08

Re: PHP FTP MP3 Upload

Posted 03 May 2012 - 11:46 AM

Unless you have register_globals ON in your php.ini -- and you most definitely should NOT -- then you never set $source_file to anything.
Was This Post Helpful? 0
  • +
  • -

#5 TechnoBear  Icon User is offline

  • D.I.C Head

Reputation: 18
  • View blog
  • Posts: 222
  • Joined: 02-November 11

Re: PHP FTP MP3 Upload

Posted 03 May 2012 - 12:15 PM

register_globals is set to off(0) and i thought $source_file was the reference to the item being passed from the form.
Was This Post Helpful? 0
  • +
  • -

#6 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6036
  • View blog
  • Posts: 23,432
  • Joined: 23-August 08

Re: PHP FTP MP3 Upload

Posted 03 May 2012 - 12:51 PM

Nope. The relevant manual page.
Was This Post Helpful? 0
  • +
  • -

#7 TechnoBear  Icon User is offline

  • D.I.C Head

Reputation: 18
  • View blog
  • Posts: 222
  • Joined: 02-November 11

Re: PHP FTP MP3 Upload

Posted 07 May 2012 - 08:30 AM

I finally managed to read through the manual page you gave me, over the weekend. the only thing i havent tried was something from the comments which was to add:

php_value    upload_max_filesize    100M
php_value    post_max_size    101M


into the .htaccess file. However, I have changed those settings in the php.ini file and do not see that doing it in .htaccess would make a vast amount of difference. I will give it a go when i get into my correct partition but is there anything else i might be doing wrong?

EDIT: Yup, putting it in the .htaccess does nothing for allowing the transfer.

This post has been edited by TechnoBear: 07 May 2012 - 09:22 AM

Was This Post Helpful? 0
  • +
  • -

#8 TechnoBear  Icon User is offline

  • D.I.C Head

Reputation: 18
  • View blog
  • Posts: 222
  • Joined: 02-November 11

Re: PHP FTP MP3 Upload

Posted 10 May 2012 - 01:13 PM

Anything else that might be able to help me with this?
Was This Post Helpful? 0
  • +
  • -

#9 Commontoast  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 9
  • Joined: 08-May 12

Re: PHP FTP MP3 Upload

Posted 13 May 2012 - 04:28 AM

Maybe there is a filesize limit or a filetype restriction on the opentranfer.com ftp server?

I got that address from the iframe tag, but i could not find any information on file-limitations on their website.
(btw. the iframe name attribute is depricated in xhtml, id will be used to identify the element, from W3Schools)
Was This Post Helpful? 0
  • +
  • -

#10 TechnoBear  Icon User is offline

  • D.I.C Head

Reputation: 18
  • View blog
  • Posts: 222
  • Joined: 02-November 11

Re: PHP FTP MP3 Upload

Posted 14 May 2012 - 10:21 AM

well i have edited php.ini to increase the filesize limit, however what it was set at before i changed it was higher than the size of the file i was attempting to upload.
Was This Post Helpful? 0
  • +
  • -

#11 Commontoast  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 9
  • Joined: 08-May 12

Re: PHP FTP MP3 Upload

Posted 14 May 2012 - 10:41 AM

Yes the PHP does not seem to be the problem at first glance, since you have tested it with another file (smaller and different filetype) and that worked.

My suggestion would be to look outside PHP to find the issue (to rule anything out).
ie. at the ftp server, which might have file-size/-type limitations.
Are you able to upload the specific mp3 file to the ftp server with a normal FTP client?

Have you tried an mp3-file of only a few KB, like the size of your image which succeeded, so you can rule out the possible size issue and confirm or discard the filetype issue?
Was This Post Helpful? 1
  • +
  • -

#12 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6036
  • View blog
  • Posts: 23,432
  • Joined: 23-August 08

Re: PHP FTP MP3 Upload

Posted 14 May 2012 - 12:52 PM

This opentransfer.com looks dodgy. Why not use a reputable service, like Amazon S3?
Was This Post Helpful? 0
  • +
  • -

#13 TechnoBear  Icon User is offline

  • D.I.C Head

Reputation: 18
  • View blog
  • Posts: 222
  • Joined: 02-November 11

Re: PHP FTP MP3 Upload

Posted 14 May 2012 - 12:56 PM

simply cause im not the one that pays the bills i was hired as a network tech and now handle pretty much anything remotely related to computers.
Was This Post Helpful? 0
  • +
  • -

#14 mccabec123  Icon User is offline

  • D.I.C Head

Reputation: 18
  • View blog
  • Posts: 225
  • Joined: 03-March 11

Re: PHP FTP MP3 Upload

Posted 16 May 2012 - 06:41 PM

I believe you should most definitely include a max size attribute to the form, at least then you know at what size you're capping it, I'm not sure what the default size is, but it could be far less than the size of an MP3, so add this:

<input type="hidden" name="MAX_FILE_SIZE" value="100000" />


The value is measured in Bytes, so it will be, 1,073,741,824 for 1 Mb. Just times that by the max size you want to allow.

Also this will stop spammers uploading huge files and crippling your server.

This post has been edited by mccabec123: 16 May 2012 - 06:42 PM

Was This Post Helpful? 0
  • +
  • -

#15 Commontoast  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 9
  • Joined: 08-May 12

Re: PHP FTP MP3 Upload

Posted 19 May 2012 - 04:25 AM

spotted a typo in the post from mccabec123
1,073,741,824 bytes is 1GB / 1024MB
1,048,576 bytes is 1MB
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1