6 Replies - 464 Views - Last Post: 31 July 2012 - 12:39 PM Rate Topic: -----

#1 laytonsdad  Icon User is offline

  • D.I.C Regular

Reputation: 62
  • View blog
  • Posts: 376
  • Joined: 30-April 10

Cant upload music or videos

Posted 26 July 2012 - 05:01 PM

Hello Everyone,

I am working on a site that needs to have videos and music uploaded but using the regular post method I get a time out response/error page before the file even uploads.

Is there a better way to do this with PHP?

Should I use FTP with php?

I don't know much about uploading videos and this has me stumped.

Any advise would be greatly appreciated.


Thank you in advance :boat:

Is This A Good Question/Topic? 0
  • +

Replies To: Cant upload music or videos

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 6469
  • View blog
  • Posts: 23,512
  • Joined: 12-June 08

Re: Cant upload music or videos

Posted 26 July 2012 - 05:04 PM

Typically showing folks the error message and the relevant chunks of code are helpful!

I believe ftp_put is still a valid form of tranferring files?
http://php.net/manua...ion.ftp-put.php
Was This Post Helpful? 1
  • +
  • -

#3 e_i_pi  Icon User is offline

  • = -1
  • member icon

Reputation: 745
  • View blog
  • Posts: 1,525
  • Joined: 30-January 09

Re: Cant upload music or videos

Posted 26 July 2012 - 05:27 PM

There's a number of reasons this could happen, a few being that you have too low an upload filesize limit, or that your provider might not allow uploading of certain filetypes. As modi123_1 said, you'll need to post errors here in order for us to be able to assist.
Was This Post Helpful? 1
  • +
  • -

#4 laytonsdad  Icon User is offline

  • D.I.C Regular

Reputation: 62
  • View blog
  • Posts: 376
  • Joined: 30-April 10

Re: Cant upload music or videos

Posted 27 July 2012 - 11:29 AM

Thank you for your responses!

Hear's the deal,

From the start

I am working on a site that I and a few others have built from scratch (no framework)for a not for profit deal.

The site has been going good until we get to the upload situation, server timed out, nothing sent back from the server. I took this as the file is too large to upload. Thinking this I began to look into using FTP_ php commands.

Start of PHP and FTP

We have created a class that will do these things but are now getting errors that we cant figure out:

Warning: ftp_put(adult fittness results.docx) [function.ftp-put]: failed to open stream: No such file or directory in /home/a8317647/public_html/class_upload.php on line 68


<?php
session_start();
include('class_upload.php');// class_upload include
$_SESSION['logged_in_user']='Admin1';//used for testing take out before launch
?>

<h1>This is to test the class_upload_lib.php</h1>
<?php
// *** Define your host, username, and password  
define('FTP_HOST', 'deleted');  
define('FTP_USER', 'deleted');  
define('FTP_PASS', 'deleted');  
  
  
// *** Include the class  
//include('ftp_class.php');  
  
// *** Create the FTP object  
$ftpObj = new file_upload_lib();//FTPClient();  


// *** Connect  
if ($ftpObj -> connect(FTP_HOST, FTP_USER, FTP_PASS)) {  
  
    // *** Then add FTP code here  
  
    echo 'connected';  
  
} else {  
    echo 'Failed to connect';  
}
/* Alternate code for above  
// *** Connect  
$ftpObj -> connect(FTP_HOST, FTP_USER, FTP_PASS);

*/

print_r($ftpObj -> getMessage()); // Optional code to display message

$dir = 'public_html/members/'.$_SESSION['logged_in_user'];      

if(!is_dir($dir)){ 
	// *** Make directory  
	$ftpObj->makeDir($dir);  
}

foreach ($_FILES["files"]["error"] as $key => $error) {
    if ($error == UPLOAD_ERR_OK) {
        $tmp_name = $_FILES["files"]["tmp_name"][$key];
        $name = $_FILES["files"]["name"][$key];
		//print $tmp_name;
		//print $name;
    }
}
//$fileFrom = 'kidlat.gif'; //This works
$fileFrom = $_FILES["files"]["name"][$key];//This does not work
$fileTo = $dir . '/' . $fileFrom;  
  
// *** Upload local file to new directory on server  
$ftpObj -> uploadFile($fileFrom, $fileTo);
print_r($ftpObj->getMessage());
?>


Class for ftp

<?php // use to test the file_upload_lib.php

class file_upload_lib  {
	// Class variables
	private $connectionId;
	private $loginOk = false;
	private $messageArray = array();
	
	public function __construct(){}
	
	private function logMessage($message){
		$this->messageArray[] = $message;
	}
	
	public function getMessage(){
		return $this->messageArray;
	}
	
	public function connect ($server, $ftpUser, $ftpPassword, $isPassive = false){  
  
		// *** Set up basic connection  
		$this->connectionId = ftp_connect($server);  
	  
		// *** Login with username and password  
		$loginResult = ftp_login($this->connectionId, $ftpUser, $ftpPassword);  
	  
		// *** Sets passive mode on/off (default off)  
		ftp_pasv($this->connectionId, $isPassive);  
	  
		// *** Check connection  
		if ((!$this->connectionId) || (!$loginResult)) {  
			$this->logMessage('FTP connection has failed!');  
			$this->logMessage('Attempted to connect to ' . $server . ' for user ' . $ftpUser, true);  
			return false;  
		} else {  
			$this->logMessage('Connected to ' . $server . ', for user ' . $ftpUser);  
			$this->loginOk = true;  
			return true;  
		}  
	}
	
	public function makeDir($directory){  
		// *** If creating a directory is successful...  
		if (@ftp_mkdir($this->connectionId, $directory)) {  
	  
			$this->logMessage('Directory "' . $directory . '" created successfully');  
			return true;  
	  
		} else {  
	  
			// *** ...Else, FAIL.  
			$this->logMessage('Failed creating directory "' . $directory . '"');  
			return false;  
		}  
	}  

	public function uploadFile ($fileFrom, $fileTo){  
		// *** Set the transfer mode  
	/*	$asciiArray = array('txt', 'csv');  
		$extension = end(explode('.', $fileFrom));  
		if (in_array($extension, $asciiArray)) {  
			$mode = FTP_ASCII;        
		} else {  
			$mode = FTP_BINARY;  
		}  
	*/  
		// *** Upload the file  
		$upload = ftp_put($this->connectionId, $fileTo, $fileFrom, FTP_BINARY);//$mode
	  
		// *** Check upload status  
		if (!$upload) {  
	  
				$this->logMessage('FTP upload has failed!');  
				return false;  
	  
			} else {  
				$this->logMessage('Uploaded "' . $fileFrom . '" as "' . $fileTo);  
				return true;  
			}  
	}

	public function changeDir($directory){  
		if (ftp_chdir($this->connectionId, $directory)) {  
			$this->logMessage('Current directory is now: ' . ftp_pwd($this->connectionId));  
			return true;  
		} else {   
			$this->logMessage('Couldn\'t change directory');  
			return false;  
		}  
	}  

	public function getDirListing($directory = '.', $parameters = '-la'){  
		// get contents of the current directory  
		$contentsArray = ftp_nlist($this->connectionId, $parameters . '  ' . $directory);  
	  
		return $contentsArray;  
	}  

	public function downloadFile ($fileFrom, $fileTo){

		// *** Set the transfer mode
		$asciiArray = array('txt', 'csv');
		$extension = end(explode('.', $fileFrom));
		if (in_array($extension, $asciiArray)) {
			$mode = FTP_ASCII;		
		} else {
			$mode = FTP_BINARY;
		}

		// open some file to write to
		//$handle = fopen($fileTo, 'w');

		// try to download $remote_file and save it to $handle
		if (ftp_get($this->connectionId, $fileTo, $fileFrom, $mode, 0)) {

		return true;
			$this->logMessage(' file "' . $fileTo . '" successfully downloaded');
		} else {

			return false;
			$this->logMessage('There was an error downloading file "' . $fileFrom . '" to "' . $fileTo . '"');
		}
	}
		
	public function __deconstruct(){
		if ($this->connectionId) {
			ftp_close($this->connectionId);
		}
	}

}

?>


This is the latest issue that has come up using ftp, while also some times getting a time out error again from the browser.

Can anyone give me ideas on how to repair this issue?
Was This Post Helpful? 0
  • +
  • -

#5 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5672
  • View blog
  • Posts: 22,520
  • Joined: 23-August 08

Re: Cant upload music or videos

Posted 27 July 2012 - 01:53 PM

You're trying to put a document to the directory created here:

$dir = 'public_html/members/'.$_SESSION['logged_in_user'];


Your warning is:

Quote

Warning: ftp_put(adult fittness results.docx) [function.ftp-put]: failed to open stream: No such file or directory in /home/a8317647/public_html/class_upload.php on line 68


What do you think your next course of action might be?
Was This Post Helpful? 1
  • +
  • -

#6 laytonsdad  Icon User is offline

  • D.I.C Regular

Reputation: 62
  • View blog
  • Posts: 376
  • Joined: 30-April 10

Re: Cant upload music or videos

Posted 27 July 2012 - 08:59 PM

View PostJackOfAllTrades, on 27 July 2012 - 01:53 PM, said:

You're trying to put a document to the directory created here:

$dir = 'public_html/members/'.$_SESSION['logged_in_user'];


Your warning is:

Quote

Warning: ftp_put(adult fittness results.docx) [function.ftp-put]: failed to open stream: No such file or directory in /home/a8317647/public_html/class_upload.php on line 68


What do you think your next course of action might be?


I think I get what your saying,

I think that because we are using the form and the method post that the file is on the server not on the client and that we need to use local files.

Is this correct or am I on a roller coaster of bad ideas?
Was This Post Helpful? 0
  • +
  • -

#7 laytonsdad  Icon User is offline

  • D.I.C Regular

Reputation: 62
  • View blog
  • Posts: 376
  • Joined: 30-April 10

Re: Cant upload music or videos

Posted 31 July 2012 - 12:39 PM

So I am sorry to say that I wasted all your time,

I was told that we were able to upload any size file we wanted to our host and that was not true and that is why all of this happened.

Again sorry to waist your time.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1