Topic: FTP and cURL -> PHP (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=29744" title="Pages that link to Topic: FTP and cURL -&amp;gt; PHP (Page 1 of 1)" rel="nofollow" >Topic: FTP and cURL -&gt; PHP <span class="small">(Page 1 of 1)</span>\

 
CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 12-03-2007 20:23

Is there a way, using cURL to FTP files without using the tmp directory? I am having an issue with file size restrictions.

Here is the code that I am using.

code:
function  image_valid($type){
    $file_types  = array(  
    'image/pjpeg'     => 'jpg',
    'image/jpeg'     => 'jpg',
    'image/jpeg'     => 'jpeg',
    'image/gif'     => 'gif',
    'image/X-PNG'    => 'png',
    'image/PNG'         => 'png',
    'image/png'     => 'png',
    'image/x-png'     => 'png',
    'image/JPG'     => 'jpg',
    'image/GIF'     => 'gif',
    'image/bmp'     => 'bmp',
    'image/bmp'     => 'BMP',
    'application/pdf' => 'PDF',
    'application/octet-stream' =>'PSD',
    );
   
    if(!array_key_exists($type, $file_types)){
        return "FALSE";
    }else{
        return "TRUE";
    }
}




if (isset($_POST['Submit'])) {	//if they hit the submit button

	if (!empty($_FILES['upload']['name']) && ($_POST['userEmail']) ) {	//and the fields are not blank
	
		$ch = curl_init();							
		$localfile = $_FILES['upload']['tmp_name'];
		$fp = fopen($localfile, 'r');		
			
			//check the file type
		 	if(image_valid($_FILES['upload']['type']) === "FALSE"){
    			//die("Image file is not valid");			//image is invalid, DIE DIE DIE!!!
    			$error = "Wrong file type";
			}else{ 	//otherwise, upload the file with cURL	 	
			
		curl_setopt($ch, CURLOPT_URL, 'ftp://my.host.com/'.$_FILES['upload']['name']);
		curl_setopt($ch, CURLOPT_USERPWD, 'username:password');
		curl_setopt($ch, CURLOPT_UPLOAD, 1);
		curl_setopt($ch, CURLOPT_INFILE, $fp);
		curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile));
		curl_exec ($ch);
		$error_no = curl_errno($ch);
		curl_close ($ch);
			
			if ($error_no > 0) {				//check on errors
				$error = "Failed to upload <br />";
					echo "Type: " . $_FILES['upload']['type'] . "<br />";
					echo "Error: " . $error_no;
			} else {
				$error = "Upload Complete <br />";
				echo "Type: " . $_FILES['upload']['type'];
			} //end error
		}
		
	} else {	//if the fields are blank
		$error = 'Please select a file.';		
	}
}



This is far from complete so ignore that it doesn't do a lot of error checking and such.

The documentation that I have found on ftp and curl is either over my head or just isn't there, but I'm having a hard time finding anything that address this issue.

What I am trying to do is simply give our customers a way to upload large files to us. We do have anonymous FTP and such, but
1. our customers are too stupid to follow directions on how to set up an FTP client.
2. our host is too stupid to compile php with ftp.

So, I just need an easy way for our customers to put in their email address, browse to the files (would be nice if it created a directory based on email or something) and upload their files. Eventually have a "Progress bar" but that's later after I get this going.

Thanks in advance!!!

Later,

C:\

jdauie
Bipolar (III) Inmate

From: Missoula, MT
Insane since: Jan 2003

posted posted 12-08-2007 09:51
quote:
So, I just need an easy way for our customers to put in their email address, browse to the files (would be nice if it created a directory based on email or something) and upload their files. Eventually have a "Progress bar" but that's later after I get this going.



Given your stated purpose, i would recommend considering a java upload component because the client-server interaction allows you to have a convenient and user-friendly interface while optimizing the communication with the server. In my experience, users find a java file-selection dialog to be reasonably simple. Obviously, you may not desire or be able use such a component, depending on your system.

Essentially, you cannot avoid using some kind of temporary storage unless the Client (browser, java, flash, ...) can upload directly to ftp. Browsers, unfortunately, do not have that built in (for html), and are remarkable inefficient with large files.

Edit:
I'm not sure what the reason is for using ftp at all if the clients are not taking advantage of it.

(Edited by jdauie on 12-08-2007 09:57)

CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 12-08-2007 16:08
quote:

jdauie said:

Browsers, unfortunately, do not have that built in (for html), and are remarkable inefficient with large files.



That's what I have found out. Thanks

quote:

jdauie said:

Edit:
I'm not sure what the reason is for using ftp at all if the clients are not taking advantage of it.



They are taking advantage of it. But I don't have time to sit on the phone and explain to someone how to set up their FTP Client for anonymous FTP. I have instructions on our website for this purpose with directions for some of the more popular ftp clients. However...they still call and I have to sit for 1/2 hour - an hour explaining how to do it.

Thanks for the info.

Later,

C:\



Post Reply
 
Your User Name:
Your Password:
Login Options:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu