Onderstaand een code die ik heb geschreven dewelke de gebruiker toelaat een document (word / txt) te uploaded (max 2Mb) en dan via de ftp functie een foto (die meestal groter zijn) ook te uploaden.
De gebruiker maakt zijn eigen subdictory aan.
De directory aanmaak en file upload werkt, bij de ftp krijg ik steeds onderstaand warning, wat doe ik verkeerd?
Hopelijk kan iemand mij helpen.
Alvast bedankt.
de warning
Warning: ftp_put(nieuwe_foto.jpg) [function.ftp-put]: failed to open stream: No such file or directory in /home/on3php1q/public_html/redactie/upload.php on line 74
<?
/*
*/
// set errors to blanc
$errors = array();
// check if form is being submitted
if(isset($_POST['actie'])){
// get callsign uploader
$callsign = strtolower(strip_tags($_POST['callsign']));
// check if file been set
if(isset($_FILES['image'])){
// set extentions allowed for upload
$allowed_ext = array('doc','docx','txt');
// get document name
$file_name = $_FILES['image']['name'];
// get the extention and convert to lowercase
$file_ext = strtolower(end(explode('.', $file_name)));
// get the file size
$file_size = $_FILES['image']['size'];
// get the tmp location
$file_tmp = $_FILES['image']['tmp_name'];
// check if extensions are allowed
if (in_array($file_ext, $allowed_ext) === false){
$errors[] = 'Geen juiste bestands extentie, enkel doc/docx of txt zijn toegestaan!';
}
// check that file smaller than 2Mb
if ($file_size > 2097152){
$errors[] = 'Bestand te groot! Mag niet groter zijn dan 2Mb.';
}
}else{
$errors[] ='Geen bestand voor upload opgegeven!';
}
if (empty($errors)){
// upload location - fix directory + submap = callsign
$upload_location = 'documents/'.$callsign;
// if not exist create submap with callsign name
if (!file_exists($upload_location)) {
mkdir($upload_location);
}
// upload file
if (move_uploaded_file($file_tmp, $upload_location.'/'.$file_name)){
echo 'Bestand succesvol geupload. Bedankt.';
}
/*
Connect with ftp to upload photo's
*/
// FTP access parameters
$host = 'ftp.on3php.be';
$usr = 'on3php';
$pwd = '************';
// file to move:
$local_file = $_FILES['foto']['name'];
$ftp_path = '/public_html/redactie/documents/'.$callsign;
echo 'bestandsname: '.$local_file.' transfert naar: '.$ftp_path;
// connect to FTP server (port 21)
$conn_id = ftp_connect($host, 21) or die ("Could not connect to remote host");
// send access parameters
ftp_login($conn_id, $usr, $pwd) or die("FTP login not succesfull");
// perform file upload
if (ftp_put($conn_id, $ftp_path, $local_file, FTP_BINARY)){
echo "Successfully uploaded $local_file\n";
}else{
echo "There was a problem while uploading $file\n";
};
// close the FTP stream
ftp_close($conn_id);
echo '<p>';
}else{
// erorr's found - show them
foreach ($errors as $error) {
echo $error.'<br>';
}
}
}
?>
<form method="POST" action="" enctype="multipart/form-data">
Callsign: <input type="text" name="callsign" placeholder="uw callsign">
<p>
Selecteer uw bestand: <input type="file" name="image" value="Selecteer uw bestand">
<p>
Selecteer bijhorende foto: <input type="file" name="foto" value="Selecteer uw bestand">
<p>
<input type="submit" name="actie" value="Upload">
</form>
3.282 views