Avalanched
Legacy Member
PHP:
<?php
class ImageUpload {
var $ftp_server = "**";
var $ftp_user_name = "**";
var $ftp_user_pass = "**";
var $type;
function ImageUpload($type){
$sourceFile = $_FILES['source_file']['tmp_name'];
$destinationFile = $_FILES['source_file']['name'];
$this->type = $type;
$thumb = $this->resizeJPG($sourceFile,200);
//$this->uploadImage($thumb,$destinationFile);
//Maak een basis connectie aan
echo $thumb;
}
function uploadImage($thumb,$destinationFile){
$conn_id = ftp_connect($this->ftp_server);
ftp_pasv($conn_id,TRUE);
//Meldt je aan met een gebruikersnaam en wachtwoord
$login_result = ftp_login($conn_id, $this->ftp_user_name, $this->ftp_user_pass);
//Controleer de verbinding
if ((!$conn_id) || (!$login_result)) {
echo "FTP connectie is mislukt!<br />";
echo "Probeerde naar " . $this->ftp_server . " te verbinden met de gebruiker " . $this->ftp_user_name . "<br />";
exit;
} else {
//echo "Verbonden met " . $ftp_server . ", als gebruiker " . $ftp_user_name . "<br />";
}
switch ($this->type) {
case "product":
$map = "fullops.dogtrack.be/img/productmedia/";
break;
case "cat":
$map = "fullops.dogtrack.be/img/categoriemedia/";
break;
}
//Upload een bestand
ftp_chdir($conn_id, $map);
$upload = ftp_put($conn_id, $destinationFile, $thumb, FTP_BINARY);
//Controleer de upload status
if (!$upload) {
echo "FTP upload is mislukt!<br />";
} else {
echo $destinationFile . " is aan het uploaden<br />";
}
//Sluit de FTP stream
ftp_chdir($conn_id, "../../../");
ftp_close($conn_id);
}
function resizeJPG($inputFilename, $new_side){
$imagedata = getimagesize($inputFilename);
$w = $imagedata[0];
$h = $imagedata[1];
if ($h > $w) {
$new_w = ($new_side / $h) * $w;
$new_h = $new_side;
} else {
$new_h = ($new_side / $w) * $h;
$new_w = $new_side;
}
$im2 = ImageCreateTrueColor($new_w, $new_h);
$image = ImageCreateFromJpeg($inputFilename);
imagecopyResampled ($im2, $image, 0, 0, 0, 0, $new_w, $new_h, $imagedata[0], $imagedata[1]);
return $im2;
}
}
?>
Ik heb geprobeerd ftp_put($conn_id, $destinationFile, $thumb, FTP_BINARY); te gebruike, maar parameter 3 vraagt om ne string (the source filename), maar het wilt altijd de geresizede image door te sture. iemand een idee?
ahja *offtopic* weet iemand waar ge soms makkelijk een auto formatting tool vind ( mag een webtool zijn) want men code word nu tijdelijk getypt op een opensource programma die dat niet heeft.