Plaatjes uploaden naar ander domijn

Status
Niet open voor verdere reacties.

bartjuh_4

Gebruiker
Lid geworden
19 jun 2005
Berichten
225
Plaatjes uploaden naar ander domein

Hallo,
Ik heb een script nodig dat een plaatje naar een ander domein (ftp) upload.

Ik heb wat rondgekeken en geprobeert maar ik kom er niet uit.

Kan iemand mij hiermee helpen?

Alvast bedankt!

Bart van Asselt
 
Laatst bewerkt:
Ik weet niet waar je op gezocht hebt maar ik heb dit voor je gevonden dankzij Google met de zoekwoorden PHP FTP :rolleyes:
 
Zou je zo vriendelijk willen zijn om de oplossing hier dan te plaatsen en de status op opgelost willen zetten?
 
Okee, ik gebruik het volgende script:

PHP:
<?php 

function ftplistdir($conn_id, $dir){
    $fold_no = array(".", "..", "cgi-data", "comp", "zuern", "counter");
    $list = ftp_nlist( $conn_id, $dir );
    foreach($list as $file){
        if (ftp_size($conn_id, $dir ."/".$file)== -1){
            if (in_array($file, $fold_no)) {
                print $file ." Ueberspringe ausgeschlossenes Verzeichnis.<br>";
            } else {
                $geslist[]= $dir ."/". $file;
                $temp=ftplistdir($conn_id, $dir ."/". $file);
                $geslist=array_merge($geslist, $temp);
            }
        }else{
            $geslist[]= $dir ."/". $file;
        }
    }
    return $geslist;
}

    $current_dir = "/var/www/html/album";
    // connection settings
    $ftp_server = "";  //address of ftp server (leave out ftp://)
    $ftp_user_name = ".nl"; // Username
    $ftp_user_pass = "";   // Password
    $conn_id = ftp_connect($ftp_server);        // set up basic connection
    // login with username and password, or give invalid user message
    $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass) or die("<h1>You do not have access to this ftp server!</h1>");


if ($HTTP_SERVER_VARS["REQUEST_METHOD"] == "POST") 
{

$naam = $_POST["naam"];
if ($naam)
{
$newdir = $current_dir . "/" . $naam;
$maak = ftp_mkdir($conn_id,$newdir);
$maak2 = ftp_mkdir($conn_id,$newdir.'/thumb');
$maak3 = ftp_mkdir($conn_id,$newdir.'/thumbgroot');

    $chmod_cmd = "CHMOD 0777 " . $newdir;
    $chmod = ftp_site($conn_id, $chmod_cmd);
    
    $chmod_cmd2 = "CHMOD 0777 " . $newdir.'/thumb';
    $chmod2 = ftp_site($conn_id, $chmod_cmd2);
    
    $chmod_cmd3 = "CHMOD 0777 " . $newdir.'/thumbgroot';
    $chmod3 = ftp_site($conn_id, $chmod_cmd3);    

// controleer de map status
if (!$chmod || !$chmod2 || !$chmod3) {
       echo "Kon geen map aanmaken";
   }

if (!$maak || !$maak2 || !$maak3) {
echo "Kon geen map aanmaken";
   }

    $destination_path = "/var/www/html/album/$naam";
}else{
    $destination_path = "/var/www/html/album";
}
$myFile = $_FILES['file']; // This will make an array out of the file information that was stored.
    $file = $myFile['tmp_name'];  //Converts the array into a new string containing the path name on the server where your file is.
    $myFileName = $_POST['MyFile']; //Retrieve file path and file name   
    $myfile_replace = str_replace('\\', '/', $myFileName);    //convert path for use with unix
    $myfile = basename($myfile_replace);    //extract file name from path     
    $destination_file = "$destination_path/".$myfile;  //where you want to throw the file on the webserver (relative to your login dir)
    $upload = ftp_put($conn_id, $destination_file, $file, FTP_BINARY);  // upload the file
    if (!$upload) {  // check upload status
        echo "<h2>FTP upload of $myFileName has failed!</h2> <br />";
    }
echo "gelukt!";
}

$dir = ftplistdir($conn_id, $current_dir);

$select = "<option>Ik maak een nieuw album</option>";

$count = "1";
if(!empty($dir))
{
    foreach($dir as $directory)
    {
if ($count <= "5")    
$select .=  "<option value=\"".$map.$directory."\">".ucfirst($directory)."</option>";
$count++;
    }
}
?>
<form name="form" enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" >
Kies een .JPG bestand om te uploaden naar je foto album:<br />
Albumnaam (nieuw album maken)
<br />
<input type="text" name="naam" />
<br /><br />
<select><?=$select?></select>
<br /><br />
<input type="file" name="file" accept="text/plain" onChange="MyFile.value=file.value" />
<input name="MyFile" type="hidden" id="MyFile" tabindex="99" size="1" />
<br /><br />
<input type="submit" name="submit" value="upload" style="vertical-align:middle" /><br /><br />
</form>
<?
ftp_close($conn_id); // close the FTP stream
?>

Alleen zie ik nu net dat ik weer een vraag heb gecreerd. Het plaatje dat ik upload moet eerst nog verkleind worden en dan worden geupload. hoe doe ik dat?
 
Je zult dan wat met deze variabelen moeten doen
PHP:
$myFile = $_FILES['file']; // This will make an array out of the file information that was stored. 
$file = $myFile['tmp_name'];  //Converts the array into a new string containing the path name on the server where your file is. 
$myFileName = $_POST['MyFile']; //Retrieve file path and file name
 
Laatst bewerkt:
Dat kan m.b.v. imagecopyresampled. Zijn op internet ook vast wel genoeg scripts over te vinden.

Noot: het plaatje moet eerst worden geüpload en dan pas worden verkleind (geschaald). Je kan niet client-side resizen, mits je daar een applicatie voor schrijft (C#, C++, Java oid).
 
Dat kan m.b.v. imagecopyresampled. Zijn op internet ook vast wel genoeg scripts over te vinden.

Noot: het plaatje moet eerst worden geüpload en dan pas worden verkleind (geschaald). Je kan niet client-side resizen, mits je daar een applicatie voor schrijft (C#, C++, Java oid).

Dat snap ik, dat bedoelde ik dus ook:')
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan