Answer the question
In order to leave comments, you need to log in
Uploading multiple photos?
Hello! I wrote a code for loading images, it works fine, it only loads one image, I need to have several and I can name them for example: 1.jpg, 2.jpg and so on, in my example the image is called 10, how to do it? Thank you
<html>
<head>
<meta charset=utf-8>
</head>
<?php
// В PHP 4.1.0 и более ранних версиях следует использовать $HTTP_POST_FILES
// вместо $_FILES.
$uploaddir = 'images/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
$filename = '10'; // имя файла
$uploadfile = $uploaddir . DIRECTORY_SEPARATOR . $filename . '.' . pathinfo($_FILES['userfile']['name'], PATHINFO_EXTENSION);
echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "Файл корректен и был успешно загружен.\n";
} else {
echo "Возможная атака с помощью файловой загрузки!\n";
}
print "</pre>";
?>
Answer the question
In order to leave comments, you need to log in
1) The code is terrible. Then echo, then print ...
2) Solution based on your code (really, as if he just got out of the sewer):
$uploaddir = 'images/';
foreach($_FILES['userfile']['name'] as $i=>$name){
$uploadfile = $uploaddir . basename($name);
$filename = $i;
$uploadfile = $uploaddir . DIRECTORY_SEPARATOR . $filename . '.' . pathinfo($name, PATHINFO_EXTENSION);
echo '<pre>';
if (move_uploaded_file($_FILES['userfile'][$i]['tmp_name'], $uploadfile)) {
echo "Файл корректен и был успешно загружен.\n";
} else {
echo "Возможная атака с помощью файловой загрузки!\n";
}
print "</pre>";
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question