Topic awaiting preservation: FTP and cURL -> PHP (Page 1 of 1) |
|
---|---|
Maniac (V) Inmate From: there...no..there..... |
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. 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.'; } }
|
Bipolar (III) Inmate From: Missoula, MT |
posted 12-08-2007 09:51
quote:
|
Maniac (V) Inmate From: there...no..there..... |
posted 12-08-2007 16:08
quote:
quote:
|