我正在创建一个表格,用于将照片上传到比赛中。我在桌面版本中没有任何问题,但智能手机存在的问题是每张照片都被加载为" image.jpeg"或" image.jpg"从而阻止上传下一个,因为它检测到同名图像。我怎样才能克服这个问题? 这是我的代码:
<?php
$target_dir = "uploads/";
$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"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "Il file selezionato non è un'immagine. ";
$uploadOk = 0;
}
}
// Check if file already exists
if (file_exists($target_file)) {
echo "Spiacente, una foto con lo stesso nome è già stata inviata. ";
$uploadOk = 0;
}
// Check file size 500kb
if ($_FILES["fileToUpload"]["size"] > 2000000) {
echo "Spiacente, le dimesioni della foto superano il limite consentito. ";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
echo "Spiacente, i formati consentiti sono jpg e png. ";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Spiacente la tua foto non è stata inviata. ";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
@mail($email_to, $email_subject, $email_message, $headers);
echo "Messaggio Inviato. La tua foto ". basename( $_FILES["fileToUpload"]["name"]). " è stata inviata con successo. ";
} else {
echo "Spiacente, si è verificato un errore nel caricamento della tua foto. ";
}
}
?>
答案 0 :(得分:0)
检查文件是否存在,如果存在,则创建一个附加时间的新文件名(或类似的东西),然后移动上传的文件。
下面给出了一个样本,你应该修改它以满足你的需要
SELECT pl.id, pl.location_id, pl.mois, pl.annee, pl.loyer_paye,
l.loyer, l.charges, l.locataire_id, laire.nom, laire.prenom,
l.chambre_id, c.numero, c.etage, c.maison_id, m.titre_crm
FROM
(
SELECT spl.id, spl.location_id, spl.mois, spl.annee, spl.loyer_paye
FROM locations sl
LEFT OUTER JOIN
(
SELECT id, location_id, mois, annee, loyer_paye
FROM paiement_loyer
UNION
SELECT 9999, usl.id, (MONTH(NOW())-1), YEAR(NOW()), 0
FROM locations usl
LEFT OUTER JOIN paiement_loyer pl1
ON usl.id = pl1.location_id
WHERE pl1.location_id IS NULL
SELECT 9999, usl.id, (MONTH(NOW())-1), YEAR(NOW()), 0
FROM locations usl
LEFT OUTER JOIN paiement_loyer pl2
ON usl.id = pl1.location_id
AND pl2.annee = YEAR(NOW())
AND pl2.mois=(MONTH(NOW())-1)
WHERE pl2.location_id IS NULL
) spl ON sl.id = spl.location_id
WHERE CURDATE() BETWEEN sl.date_debut AND sl.date_fin
) pl
JOIN locations l ON pl.location_id = l.id
JOIN locataires laire ON l.locataire_id = laire.id
JOIN chambres c ON l.chambre_id = c.id
JOIN maisons m ON c.maison_id = m.id
ORDER BY TRIM(UPPER(m.titre_crm)), c.numero, pl.annee, pl.mois