Codice PHP:
<?php
session_start();
include("config.php");
include("connect_db.php");
// routine controllo data
date_default_timezone_set('Europe/Rome');
$date_current = date('Y-m-d');
Function GetTimeStamp($MySqlDate)
{
/*
Take a date in yyyy-mm-dd format and return it to the user
in a PHP timestamp
Robin 06/10/1999
*/
$date_array = explode("-",$MySqlDate); // split the array
$var_year = $date_array[0];
$var_month = $date_array[1];
$var_day = $date_array[2];
$var_timestamp = mktime(0,0,0,$var_month, $var_day, $var_year);
return($var_timestamp); // return it to the user
}
Function GetTimeStamp_back($MySqlDate_back)
{
/*
Take a date in yyyy-mm-dd format and return it to the user
in a PHP timestamp
Robin 06/10/1999
*/
$date_array_back = explode("/",$MySqlDate_back); // split the array
$var_day_back = $date_array_back[0];
$var_month_back = $date_array_back[1];
$var_year_back = $date_array_back[2];
$var_timestamp_back = mktime(0,0,0,$var_month_back, $var_day_back, $var_year_back);
return($var_timestamp_back); // return it to the user
}
function datediff($tipo, $partenza, $fine)
{
switch ($tipo)
{
case "A" : $tipo = 365;
break;
case "M" : $tipo = (365 / 12);
break;
case "S" : $tipo = (365 / 52);
break;
case "G" : $tipo = 1;
break;
}
$arr_partenza = explode("/", $partenza);
$partenza_gg = $arr_partenza[0];
$partenza_mm = $arr_partenza[1];
$partenza_aa = $arr_partenza[2];
$arr_fine = explode("/", $fine);
$fine_gg = $arr_fine[0];
$fine_mm = $arr_fine[1];
$fine_aa = $arr_fine[2];
$date_diff = mktime(12, 0, 0, $fine_mm, $fine_gg, $fine_aa) - mktime(12, 0, 0, $partenza_mm, $partenza_gg, $partenza_aa);
$date_diff = floor(($date_diff / 60 / 60 / 24) / $tipo);
return $date_diff;
}
function FirstLastWeek($data) {
list($giorno, $mese, $anno) = explode('/', $data);
$w = date('w', mktime(0,0,0, $mese, $giorno, $anno));
$day['W'] = date('W', mktime(0,0,0, $mese, $giorno, $anno));
$giorni=array(0=>'Domenica', 1=>'Lunedì', 2=>'Martedì',3=>'Mercoledì',
4=>'Giovedì', 5=>'Venerdì', 6=>'Sabato');
$day['giorno'] = $giorni[$w];
$day['anno'] = $anno;
if($w == 0 ) {
$day['lunedi'] = date('d/m/Y', mktime(0,0,0, $mese, $giorno - 6, $anno));
$day['domenica'] = date('d/m/Y', mktime(0,0,0, $mese, $giorno, $anno));
} else {
$day['lunedi'] = date('d/m/Y', mktime(0,0,0, $mese, $giorno - $w + 1, $anno));
$day['domenica'] = date('d/m/Y', mktime(0,0,0, $mese, $giorno - $w + 7, $anno));
}
return $day;
}
// set monday and today on d/m/y and sql type
$today = date("d/m/Y" ,GetTimeStamp($date_current));
$day = FirstLastWeek($today);
$sql_monday = date("Y-m-d", GetTimeStamp_back($day[lunedi]));
$gg_passati = datediff("G", $day[lunedi], $today);
// controllo numero e data upload
$sql_upload_weekly = "SELECT * FROM gallery_photos WHERE user = '".$_SESSION['identificativo']."' AND date BETWEEN '".$sql_monday."' AND '".$date_current."' ";
$query_upload_weekly = mysql_query($sql_upload_weekly, $cn);
$quanti_upload_weekly = mysql_num_rows($query_upload_weekly);
$sql_upload_daily = "SELECT * FROM gallery_photos WHERE user = '".$_SESSION['identificativo']."' AND date ='".$date_current."' ";
$query_upload_daily = mysql_query($sql_upload_daily, $cn);
$quanti_upload_daily = mysql_num_rows($query_upload_daily);
if ($_SESSION['max_upload'] == 'all') { $check_upload ='1'; $message='You have no limit to upload photo;';} else {
if ($_SESSION['frequency']=='weekly') {
$frequency='This week';
if ($quanti_upload_weekly < $_SESSION['max_upload']) {$check_upload = '1';} else {$check_upload ='0'; $message='You have reached your maximum upload limit! According to your setting you can upload only '.$_SESSION['max_upload'].' photo/week.
'.$frequency.' your upload were '.$quanti_upload_weekly.';';}
}
elseif ($_SESSION['frequency']=='daily') {
$frequency='Today';
if ($quanti_upload_daily < $_SESSION['max_upload']) {$check_upload ='1';} else {$check_upload ='0'; $message='You have reached your maximum upload limit! According to your setting you can upload only '.$_SESSION['max_upload'].' photo/day.
'.$frequency.' your upload were '.$quanti_upload_daily.';';}
}
}
if ( $check_upload == '0' ) {
echo "<font color='gray'> I'm sorry! ".$message."</font>";
} else {
$images_dir = "photos";
$sql_category = "SELECT category_id, category_name FROM gallery_category WHERE category_id < 11 ";
?>
<div id="testo">
<form action='my_account.php' method='post' name='upload_form' style="border:0px" enctype="multipart/form-data">
<table width='100%' height="190" border='0' align='center' style='width: 100%;'>
<tr>
<td>
[b]C a t e g o r y[/b]:[img]picture_library/shim.gif[/img]
<select name='category' id="category" class="selectable" >
<?php
$rs_category = mysql_query($sql_category, $cn);
while($row_cat = mysql_fetch_array($rs_category))
{?>
<option value="<?php echo $row_cat['0'];?>"> <?php echo $row_cat['1'];?></option>
<?php } ?>
</select>
</td>
</tr>
<tr>
<td>
[b]P h o t o[/b] :[img]picture_library/shim.gif[/img]
<input name='photo_filename' type='file' size="23" />
</td>
</tr>
<tr>
<td>
[b] T i t l e[/b]: [img]picture_library/shim.gif[/img]
<input name='photo_caption' maxlength="25" size="23">
</td>
</tr>
<tr>
<td>
[b]E q u i p m e n t[/b]: [img]picture_library/shim.gif[/img]
<input name='equipment' maxlength="100" size="90">
</td>
</tr>
<tr>
<td height="26">
<input type='submit' name='submit' value='Add Photo and Wait' />
</td>
</tr>
</table>
</form>
<font color="red" size="3">[b]
MAXIMUM FILE SIZE:300kb; ONLY IMAGES LARGER SIDE: 900px;NO BORDER & SIGNATURE,OR WILL BE REJECTED.</p>[/b]</font>
<font color="red" size="3">[b]
PLEASE INSERT PHOTO DATA AND TITLE.THANKS</p>[/b]</font>
<font color="red" size="4">To Read:</font></p>
<font color="red" size="4">Some images may be rejected,this does not mean they are ugly or badly made but simply do not fit the style on this site.No there demoralized if we refuse one your photo but continue to post.Thanks</font></p>
</div> <?php
}
?>
Grazie a tutti