Hulp bij php ftp script

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Marc Huyghebaert

Marc Huyghebaert

03/02/2013 18:04:12
Quote Anchor link
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

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?
/*

*/

// 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>
Gewijzigd op 03/02/2013 19:00:06 door Marc Huyghebaert
 
PHP hulp

PHP hulp

19/04/2024 03:47:48
 
Jordi Kroon

Jordi Kroon

03/02/2013 18:50:49
Quote Anchor link
Even je wachtwoord uit de code halen voordat het word misbruikt.

Bekijk de fout goed. Het pad van het bestand is onjuist.
 
Marc Huyghebaert

Marc Huyghebaert

03/02/2013 19:01:41
Quote Anchor link
zou toch dezelfde moeten zijn zoals ik het een ftp client naar de site ga of niet
 
- SanThe -

- SanThe -

04/02/2013 09:30:17
Quote Anchor link
Dit is slechts een naam:
$local_file = $_FILES['foto']['name'];

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

En waarom met FTP?
 
Marc Huyghebaert

Marc Huyghebaert

04/02/2013 09:49:49
Quote Anchor link
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

Toevoeging op 04/02/2013 09:52:59:

- 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
 
- SanThe -

- SanThe -

04/02/2013 10:06:49
Quote Anchor link
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.
 
Frank Nietbelangrijk

Frank Nietbelangrijk

04/02/2013 14:21:32
Quote Anchor link
Kijk eens naar http://www.uploadify.com
 



Overzicht Reageren

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.