نمایش نتایج 1 تا 6 از 6

نام تاپیک: محدودیت برای آپلود فایل

Hybrid View

پست قبلی پست قبلی   پست بعدی پست بعدی
  1. #1
    کاربر دائمی آواتار soroush.r70
    تاریخ عضویت
    فروردین 1389
    محل زندگی
    مازندران - آمل
    پست
    1,157

    محدودیت برای آپلود فایل

    دوستان من یه فرم آپلود فایل دارم می خوام براش محدودیت زارم مثل اینکه اگه حجمش از 3MB بیشتر بود پیغام بده و فقط فرمت هایی که من می گم آپلود بشه در غیر این صورت پیغام خطا بده.

    حجم فایل = 3MB در غیر این صورت پیغام خطا و آپلود نشود.

    نوع فایل مشخص = zip - rar - pdf - jpg - bmp - gif - doc در غیر این صورت خطا و فایل آپلود نشود.

  2. #2
    کاربر دائمی
    تاریخ عضویت
    آذر 1387
    محل زندگی
    اهل کاشانم
    پست
    746

    نقل قول: محدودیت برای آپلود فایل

    با سلام
    if ($_FILES["file"]["size"] < 220000)
    {
    if ($_FILES["file"]["error"] > 0)
    {
    //echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
    else
    {
    //echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    //$nam= $_FILES["file"]["type"];
    //echo $nam;
    if (file_exists("../picture/" . $_FILES["file"]["name"]))
    {
    echo($_FILES["file"]["name"] . " already exists. ");
    }
    else
    {
    move_uploaded_file($_FILES["file"]["tmp_name"], "../picture/" . $_FILES["file"]["name"]);

  3. #3
    کاربر دائمی
    تاریخ عضویت
    آذر 1387
    محل زندگی
    اهل کاشانم
    پست
    746

    نقل قول: محدودیت برای آپلود فایل

    <?php 
    // begin Dave B's Q&D file upload security code
    $allowedExtensions = array("txt","csv","htm","html","xml",
    "css","doc","xls","rtf","ppt","pdf","swf","flv","a vi",
    "wmv","mov","jpg","jpeg","gif","png");
    foreach ($_FILES as $file) {
    if ($file['tmp_name'] > '') {
    if (!in_array(end(explode(".",
    strtolower($file['name']))),
    $allowedExtensions)) {
    die($file['name'].' is an invalid file type!<br/>'.
    '<a href="javascript:history.go(-1);">'.
    '&lt;&lt Go Back</a>');
    }
    }
    }
    // end Dave B's Q&D file upload security code
    ?>

  4. #4
    کاربر دائمی
    تاریخ عضویت
    آذر 1387
    محل زندگی
    اهل کاشانم
    پست
    746

    نقل قول: محدودیت برای آپلود فایل

    <?php

    $file = $_FILES['userfile'];

    $allowedExtensions = array("txt", "rtf", "doc");

    function isAllowedExtension($fileName) {
    global $allowedExtensions;

    return in_array(end(explode(".", $fileName)), $allowedExtensions);
    }

    if($file['error'] == UPLOAD_ERR_OK) {
    if(isAllowedExtension($file['name'])) {
    # Do uploading here
    } else {
    echo "Invalid file type";
    }
    } else die("Cannot upload");

    ?>

  5. #5
    کاربر دائمی
    تاریخ عضویت
    آذر 1387
    محل زندگی
    اهل کاشانم
    پست
    746

    نقل قول: محدودیت برای آپلود فایل

    <?php
    // Configuration - Your Options
    $allowed_filetypes = array('.jpg','.gif','.bmp','.png'); // These will be the types of file that will pass the validation.
    $max_filesize = 524288; // Maximum filesize in BYTES (currently 0.5MB).
    $upload_path = './files/'; // The place the files will be uploaded to (currently a 'files' directory).

    $filename = $_FILES['userfile']['name']; // Get the name of the file (including file extension).
    $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.

    // Check if the filetype is allowed, if not DIE and inform the user.
    if(!in_array($ext,$allowed_filetypes))
    die('The file you attempted to upload is not allowed.');

    // Now check the filesize, if it is too large then DIE and inform the user.
    if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
    die('The file you attempted to upload is too large.');

    // Check if we can upload to the specified path, if not DIE and inform the user.
    if(!is_writable($upload_path))
    die('You cannot upload to the specified directory, please CHMOD it to 777.');

    // Upload the file to your specified path.
    if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename))
    echo 'Your file upload was successful, view the file <a href="' . $upload_path . $filename . '" title="Your File">here</a>'; // It worked.
    else
    echo 'There was an error during the file upload. Please try again.'; // It failed :(.

    ?>

  6. #6

    نقل قول: محدودیت برای آپلود فایل

    با سلام، این کد رو تست کنید. امیدوارم به درد بخوره:

    if(isset($_FILES['photo'])) {
    $photo = &$_FILES['photo'];
    $ext = substr($photo['name'], -3);
    $exts = array('doc', 'gif', 'bmp', 'jpg', 'pdf', 'rar', 'zip');
    if($photo['size'] > 3145728) {
    echo 'Size error (must be < 3MB)<br/>'."\n";
    }
    elseif(in_array($ext, $exts)) {
    move_uploaded_file($photo['tmp_name'], 'images/'.$photo['name']);
    }
    else {
    echo 'Invalid file (only ';
    foreach($exts as $ext) {
    echo '".'.$ext.'" ';
    }
    echo 'extensions are allowed<br/>'."\n";
    }
    }

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •