تغيرات در خروجي كد

atk

Active Member
سلام دوستان من يك كدي دارم كه خروجي اش به شكل زير است:
PHP:
array(4) { ["url"]=> string(73) "http://www.oswd.ir/downloads/theme.zip" ["amount"]=> string(4) "2911" ["size"]=> int(345385) ["lastmodified"]=> int(1240433734) }

اگر بخواهم اين كد به اين شكل تغيير كند بايد چه كار كنم:
تعداد دانلود: 2911
سايز: 345385 (اين عدد بايت است بايد به كيلوبايت تيديل بشود)
آخرين ويرايش: 1240433734 (اين عدد نميدونم چي هست ولي بايد به تاريخ تبديل شود)

يا علي
 

P.H.P

Member
سلام

تبدیل Bytes به Kb

کد:
Explained
1024 bytes = 1 Kilobyte (KB)

PHP:
$size = 345385;
echo round(($size / 1024), 2);

تبدیل time به date

PHP:
$time = 1240433734;
echo date('Y-m-d', $time);

موفق
 
  • Like
Reactions: atk

atk

Active Member
سلام
من چطوري مي تونم سايز رو از آن آرايه به گيرم و مساوي size$ قرار دهم؟

يا علي
 

atk

Active Member
اين در واقع يك پلاگين wordpress است. براي نمايش دادن اطلاعات يك فايل براي دانلود، از قبيل تعداد دانلود، حجم فايل و ... .
اين مطلبي كه مي گذارم راهنمايي خود سايت اصلي مي باشد:
کد:
Retrieving download information from PHP
Since version 0.6 is it possible to get information about the downloads using PHP, so you can use this information directly in your templates or in you own plugins. Only one function is important at the moment:

download_information($download_name, $return_information = DOWNLOAD_URL | DOWNLOAD_AMOUNT)

This function will return an array with the requested information. You can specify what information to return by the argument $return_information. The file downloadcounter-options.php contains the correct define statements which can be used. Currently only URL, Amount, Size and Last Modified Date are available.

Using the code

$info = download_information(wp-downloadcounter.zip, DOWNLOAD_URL | DOWNLOAD_AMOUNT | DOWNLOAD_SIZE | DOWNLOAD_LASTMODIFIED | DOWNLOAD_LASTDOWNLOAD);
var_dump($info);

returns:

array(4) { ["url"]=> string(73) "http://projects.bovendeur.org/downloads/wp-downloadcounter.zip" ["amount"]=> string(4) "2913" ["size"]=> int(345385) ["lastmodified"]=> int(1240433734) }

من از اين كد استفاده مي كنم:
PHP:
$info = download_information(wp-downloadcounter.zip, DOWNLOAD_URL | DOWNLOAD_AMOUNT | DOWNLOAD_SIZE | DOWNLOAD_LASTMODIFIED | DOWNLOAD_LASTDOWNLOAD);
var_dump($info);
و اين كد را باز مي گرداند:

PHP:
array(4) { ["url"]=> string(73) "http://projects.bovendeur.org/downloads/wp-downloadcounter.zip" ["amount"]=> string(4) "2913" ["size"]=> int(345385) ["lastmodified"]=> int(1240433734) }

يا علي
 

P.H.P

Member
اطلاع ندارم ولی چون این رو به صورت خروجی میده حتما تابعی هم برای خوندنش داره
 
  • Like
Reactions: atk

asdb20

Member
خروجی این تابع ارایه هست
PHP:
print     "url   : ". $info['url']    ."<br />
        amount : ". $info['amount'] . "<br />
        size   : ". $info['size']   . "<br />
        lastmod: ". $info['lastmodified'];
 
  • Like
Reactions: atk

P.H.P

Member
PHP:
$size = $info['size'];
echo round(($size / 1024), 2);

PHP:
$time = $info['lastmodified'];
echo date('Y-m-d', $time);
 
  • Like
Reactions: atk

جدیدترین ارسال ها

بالا