<?php
$orgWidth = 800;
$orgHeight = 600;
$thumbRatio = 5;
list
($width, $height) = getimagesize($_FILES['Filedata']['tmp_name']); if ($width/$height > $orgWidth/$orgHeight)
{
$orgHeight = ceil($height/($width/$orgWidth)); } else {
$orgWidth = ceil($width/($height/$orgHeight)); }
$thumbWidth = ceil($orgWidth/$thumbRatio); $thumbHeight = ceil($orgHeight/$thumbRatio); $source = imagecreatefromjpeg($_FILES['Filedata']['tmp_name']);
$orginal = imagecreatetruecolor($orgWidth, $orgHeight);
imagecopyresampled($orginal, $source, 0, 0, 0, 0, $orgWidth, $orgHeight, $width, $height);
imagejpeg($orginal);
$thumb = imagecreatetruecolor($thumbWidth, $thumbHeight);
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $width, $height);
imagejpeg($thumb);
$connection = ftp_connect($ftp['host']);
ftp_login($connection, $ftp['user'], $ftp['pass']);
ftp_chdir($connection, 'www');
ftp_chdir($connection, $ftp['orgDir']);
ftp_fput($connection, $_FILES['Filedata']['name'] , $orginal, FTP_BINARY);
ftp_chdir($connection, $ftp['thumbDir']);
ftp_fput($connection, $_FILES['Filedata']['name'] , $thumb, FTP_BINARY);
ftp_close($connection);
?>
Powyższy kod służy do zmiany rozmiaru zdjęcia wgranego za pomocą formularza i wgranie jego pomniejszonych wersji (dużej i miniaturki) na zdalny serwer FTP. Skrypt zwraca błąd:
Warning: ftp_fput() expects parameter 3 to be resourceJak więc zamienić plik, który trzymam w zmiennej na strumień bez konieczności zapisywania pliku na serwerze i skorzystanie z funkcji
ftp_put" title="Zobacz w manualu PHP" target="_manual?