par
accrok » 12 janv. 2009, 13:29
Bonjour je suis débutant en php, et je souhaiterais transformer une fonctions qui donne la possibilité d'uploader des fichiers images, en une fonctions idem (du moins au plus proche) qui donne la possibilités d'uploader des fichiers vidéos (.mov, .swf, .flv, .wmv) .
Est ce possible ?
Et si oui, comment dois je procéder, auriez vous un bon tuto simple pour un débutant, ou est ce que quelqu'un pourrait me venir en aide ?
Voici la fonction en questions !!!
PS: je sais que cela va être dur de capturer automatiquement la première image de la vidéo pour en faire un thumbnails, donc je veut zapper cette possibilité et la transformer par une possibilité qui me permettrais d'uploader moi même le thumbs pour cette vidéos.
Code : Tout sélectionner
function uploadimage($inputName, $uploadDir)
{
$image = $_FILES[$inputName];
$imagePath = '';
$thumbnailPath = '';
// if a file is given
if (trim($image['tmp_name']) != '') {
$ext = substr(strrchr($image['name'], "."), 1); //$extensions[$image['type']];
// generate a random new file name to avoid name conflict
$imagePath = md5(rand() * time()) . ".$ext";
list($width, $height, $type, $attr) = getimagesize($image['tmp_name']);
// make sure the image width does not exceed the
// maximum allowed width
if (LIMIT_WIDTH && $width > MAX_IMAGE_WIDTH) {
$result = createThumbnail($image['tmp_name'], $uploadDir . $imagePath, MAX_IMAGE_WIDTH);
$imagePath = $result;
} else {
$result = move_uploaded_file($image['tmp_name'], $uploadDir . $imagePath);
}
if ($result) {
// create thumbnail
$thumbnailPath = md5(rand() * time()) . ".$ext";
$result = createThumbnail($uploadDir . $imagePath, $uploadDir . $thumbnailPath, THUMBNAIL_WIDTH);
// create thumbnail failed, delete the image
if (!$result) {
unlink($uploadDir . $imagePath);
$imagePath = $thumbnailPath = '';
} else {
$thumbnailPath = $result;
}
} else {
// the product cannot be upload / resized
$imagePath = $thumbnailPath = '';
}
}
return array('image' => $imagePath, 'thumbnail' => $thumbnailPath);
}
[/php]
Bonjour je suis débutant en php, et je souhaiterais transformer une fonctions qui donne la possibilité d'uploader des fichiers images, en une fonctions idem (du moins au plus proche) qui donne la possibilités d'uploader des fichiers vidéos (.mov, .swf, .flv, .wmv) .
Est ce possible ?
Et si oui, comment dois je procéder, auriez vous un bon tuto simple pour un débutant, ou est ce que quelqu'un pourrait me venir en aide ?
Voici la fonction en questions !!!
PS: je sais que cela va être dur de capturer automatiquement la première image de la vidéo pour en faire un thumbnails, donc je veut zapper cette possibilité et la transformer par une possibilité qui me permettrais d'uploader moi même le thumbs pour cette vidéos.
[code]
function uploadimage($inputName, $uploadDir)
{
$image = $_FILES[$inputName];
$imagePath = '';
$thumbnailPath = '';
// if a file is given
if (trim($image['tmp_name']) != '') {
$ext = substr(strrchr($image['name'], "."), 1); //$extensions[$image['type']];
// generate a random new file name to avoid name conflict
$imagePath = md5(rand() * time()) . ".$ext";
list($width, $height, $type, $attr) = getimagesize($image['tmp_name']);
// make sure the image width does not exceed the
// maximum allowed width
if (LIMIT_WIDTH && $width > MAX_IMAGE_WIDTH) {
$result = createThumbnail($image['tmp_name'], $uploadDir . $imagePath, MAX_IMAGE_WIDTH);
$imagePath = $result;
} else {
$result = move_uploaded_file($image['tmp_name'], $uploadDir . $imagePath);
}
if ($result) {
// create thumbnail
$thumbnailPath = md5(rand() * time()) . ".$ext";
$result = createThumbnail($uploadDir . $imagePath, $uploadDir . $thumbnailPath, THUMBNAIL_WIDTH);
// create thumbnail failed, delete the image
if (!$result) {
unlink($uploadDir . $imagePath);
$imagePath = $thumbnailPath = '';
} else {
$thumbnailPath = $result;
}
} else {
// the product cannot be upload / resized
$imagePath = $thumbnailPath = '';
}
}
return array('image' => $imagePath, 'thumbnail' => $thumbnailPath);
}
[/code][/php]