Page Upload Lines en PHP

If you need help building your website, this is the place to hang out. If you're an HTML, PHP, Perl or web database geek, check it out. / Si vous avez besoin d'aide pour construire votre site web, c'est le forum à regarder! Si vous êtes un expert en HTML, PHP, Perl ou en base de données, c'est le forum pour vous!
Post Reply
tiguil
The Passion One / Le Passionné
Posts: 190
Joined: Sat Dec 26, 2009 6:56 pm

Page Upload Lines en PHP

Post by tiguil »

Bonjour messieurs, j'aimerais créer une page upload de trio PHP.

J'ai trouvé des lignes de codes pour un upload image sur internet. Je veux savoir si c'Est possible d'ajuster et si oui, ce qui doit être fait pour que tout fonctionne.

Merci à l'avance!

Page HTML qui affiche le php! :

<!DOCTYPE html>
<html>
<body>

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

</body>
</html>

Page PHP avec les fonctions :

<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "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)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
?>
Guillaume Diamond
Président de la Ligue de Hockey Simulé de l'Estrie
8 saisons FHL, 26 saisons STHS!
http://www.lhse.org
SimonT
STHS Owner / Propriétaire du STHS
Posts: 14758
Joined: Sat Oct 08, 2005 4:18 pm
Location: Montreal, Canada
Contact:

Re: Page Upload Lines en PHP

Post by SimonT »

As-tu changé ton php.ini pour accepter les upload? Je vais regardé ce que je peux faire parce c'est une très bonne idée.
-SimonT
Forum Administrator / Administrateur du Forum
STHS Owner / Propriètaire du STHS
English V2 & V3 Manual - Manuel V2 & V3 Français
tiguil
The Passion One / Le Passionné
Posts: 190
Joined: Sat Dec 26, 2009 6:56 pm

Re: Page Upload Lines en PHP

Post by tiguil »

J'utilise le websim portail, mais je fais des championnats du monde et autres parfois qui n'utilise pas le portail sur des sites très très primaire... du genre un lien pour l'index du sths et un lien pour déposer les fichiers. (J'utilise v2) Alors, je veux un code simple en php pour un upload.

Merci!
Guillaume Diamond
Président de la Ligue de Hockey Simulé de l'Estrie
8 saisons FHL, 26 saisons STHS!
http://www.lhse.org
SimonT
STHS Owner / Propriétaire du STHS
Posts: 14758
Joined: Sat Oct 08, 2005 4:18 pm
Location: Montreal, Canada
Contact:

Re: Page Upload Lines en PHP

Post by SimonT »

La prochaine version du STHS aura cette fonctionnalité! Si tu veux tester avant tout le monde, envoie-moi un courriel.
-SimonT
Forum Administrator / Administrateur du Forum
STHS Owner / Propriètaire du STHS
English V2 & V3 Manual - Manuel V2 & V3 Français
Post Reply