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>
Even je wachtwoord uit de code halen voordat het word misbruikt.

Bekijk de fout goed. Het pad van het bestand is onjuist.
zou toch dezelfde moeten zijn zoals ik het een ftp client naar de site ga of niet
Dit is slechts een naam:
$local_file = $_FILES['foto']['name'];

Het bestand zit in:
$local_file = $_FILES['foto']['tmp_name'];

En waarom met FTP?
Ik zocht/zoek een methode om grotere bestanden dan de 2Mb te kunnen uploaden.
Ik weet dat ik eventueel php.ini kan aanpassen maar weet niet hoe groot ik deze kan zetten, en kan dit zonder de php.ini definitief aan te passen maar in php, via .htaccess lukt het niet, server heeft foutmelding configuration mismatch

[size=xsmall]Toevoeging op 04/02/2013 09:52:59:[/size]

- SanThe - op 04/02/2013 09:30:17

Dit is slechts een naam:
$local_file = $_FILES['foto']['name'];

Het bestand zit in:
$local_file = $_FILES['foto']['tmp_name'];

En waarom met FTP?


Fout melding blijft dezelde trouwens
Marc Huyghebaert op 04/02/2013 09:49:49

Ik zocht/zoek een methode om grotere bestanden dan de 2Mb te kunnen uploaden.


Als het bestand in $_FILES staat is het reeds geuploaded.
Indien het dus groter is dan de max. size dan zal er een error gegeven zijn.

Reageren