Luchdaich suas faidhle a ’cleachdadh php

SSL earbsach bho dìreach $3.44
sanasan
Làimhseachadh faidhle PHP leughadh agus sgrìobhadh
Làimhseachadh faidhle a’ cleachdadh PHP

Ma tha thu airson faidhle a luchdachadh suas gu pasgan sònraichte, lean na fuasglaidhean gu h-ìosal.

Fuasgladh 1

Gu h-ìosal tha aon dòigh air faidhlichean a luchdachadh suas, tha iomadh dòigh eile ann.

<?php
$target_dir = "upload/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file, PATHINFO_EXTENSION);

// Check if image file is a actual image or fake image
if (isset($_POST["submit"])) {

    if ($target_file == "upload/") {
        $msg = "cannot be empty";
        $uploadOk = 0;
    } // Check if file already exists
    else if (file_exists($target_file)) {
        $msg = "Sorry, file already exists.";
        $uploadOk = 0;
    } // Check file size
    else if ($_FILES["fileToUpload"]["size"] > 5000000) {
        $msg = "Sorry, your file is too large.";
        $uploadOk = 0;
    } // Check if $uploadOk is set to 0 by an error
    else if ($uploadOk == 0) {
        $msg = "Sorry, your file was not uploaded.";

        // if everything is ok, try to upload file
    } else {
        if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
            $msg = "The file " . basename($_FILES["fileToUpload"]["name"]) . " has been uploaded.";
        }
    }
}

?>

Fuasgladh 2

An toiseach, sgrìobh do chòd HTML mar seo, agus na dìochuimhnich cuir ris enctype="multipart/form-data"

<form action="upload.php" method="post" enctype="multipart/form-data">
  <input type="file" name="fileToUpload" id="fileToUpload">
  <input type="submit" value="Upload Image" name="submit">
</form>

An uairsin cruthaich ainm faidhle ris an canar upload.php

SSL earbsach bho dìreach $3.44
sanasan
<?php
$path = "form/";
$target_file =  $path.basename($_FILES["fileToUpload"]["name"]);
$file=$_FILES['fileToUpload']['name'];    
$result = move_uploaded_file($_FILES['fileToUpload']['tmp_name'],$target_file.$file);
if ($result) {
    echo "file successfully uploaded";
}
else {
    echo "please select your file";
}
Làimhseachadh faidhle PHP leughadh agus sgrìobhadh
Làimhseachadh faidhle a’ cleachdadh PHP
dùin

Cùm suas ris an fhiosrachadh as ùire mu PHP!

Cha bhith sinn a’ spamadh!

SSL earbsach bho dìreach $3.44
sanasan

en English
X
Rach gu mhullaich