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

نام تاپیک: کمک در مورد آپلود عکس و آخرین رکورد

  1. #1
    کاربر تازه وارد
    تاریخ عضویت
    آذر 1384
    محل زندگی
    mashhad
    سن
    46
    پست
    33

    کمک در مورد آپلود عکس و آخرین رکورد

    با سلام
    طریقه آپلود عکس با پی اچ پی رو لازم دارم و همچنین وارد کردن اطلاعات آن در یک فیلد دیتابیس و گرفتن آی دی آخرین رکورد وارد شده داخل یک جدول را نیز با استفاده از زبان php لازم دارد
    لطفا اگه می تونید راهنماییم کنید.
    با تشکر
    مجید امیرخانی از مشهد

  2. #2
    [code]
    <html>
    <head>
    <META http-equiv="Content-Type" content="text/html; charset=windows-1256">
    </head>
    <body bgcolor="#E0E0E2">
    <?
    // org_id -> year -> id
    // aval se moteghaiere org_id, year, id ro check mikonim
    // dovom mibinim org_id sakhteh shodeh ya na

    $id=190; //IDIE sanad ke session shodeh farz kardim
    $year=86;//Sale faaaal ke sesssion shodeh farz shodeh
    $org4_id=$_POST["org_id"];
    if(isset($org_id) && isset($year) && isset($id))
    { //ife teste moteghaier
    //org_id va year pass shodeh
    if(is_dir("./attachments/".$org_id."/"))
    {
    if(is_dir("./attachments/".$org_id."/".$year."/"))
    {
    if(is_dir("./attachments/".$org_id."/".$year."/"))
    {
    $dir=opendir("./attachments/".$org_id."/".$year."/");
    $fp=fopen("./attachments/".$org_id."/".$year."/count.txt","r+");
    $count = fread ($fp,1024);
    fclose($fp);
    $fpw=fopen("./attachments/".$org_id."/".$year."/count.txt","w");
    $count = $count+1;

    fputs($fpw,$count);
    fclose($fpw);
    closedir($dir);
    if(is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name']))
    copy($HTTP_POST_FILES['userfile']['tmp_name'], "./attachments/".$org_id."/".$year."/".$org_id."_".$year."_".$id."_".$count.".jpg" );
    }
    /* else
    { // id yokh
    mkdir("./attachments/".$org_id."/".$year."/","0777");
    $dir=opendir("./attachments/".$org_id."/".$year."/");
    $fp=fopen("./attachments/".$org_id."/".$year."/count.txt","w+");
    fputs($fp,'1');
    fclose($fp);
    closedir($dir);
    if(is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name']))
    copy($HTTP_POST_FILES['userfile']['tmp_name'], "./attachments/".$org_id."/".$year."/".$org_id."_".$year."_".$id."_1.jpg" );

    } */
    }
    else
    { // year yokh
    mkdir("./attachments/".$org_id."/".$year."/","0777");
    $dir=opendir("./attachments/".$org_id."/".$year."/");
    $fp=fopen("./attachments/".$org_id."/".$year."/count.txt","w+");
    fputs($fp,'1');
    fclose($fp);
    closedir($dir);
    if(is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name']))
    copy($HTTP_POST_FILES['userfile']['tmp_name'], "./attachments/".$org_id."/".$year."/".$org_id."_".$year."_".$id."_1.jpg" );

    }
    }
    else
    {
    //forg_id mojood nist
    //$org_id ro misazeh, $Year va $id ro ham misazeh va ax ro mirizeh toosh
    mkdir("./attachments/".$org_id."/","0777");
    mkdir("./attachments/".$org_id."/".$year."/","0777");
    $dir=opendir("./attachments/".$org_id."/".$year."/");
    $fp=fopen("./attachments/".$org_id."/".$year."/count.txt","w+");
    fputs($fp,'1');
    fclose($fp);
    closedir($dir);
    copy($HTTP_POST_FILES['userfile']['tmp_name'], "./attachments/".$org_id."/".$year."/".$org_id."_".$year."_".$id."_1.jpg" );

    }

    } //ife teste moteghaiere
    ?>
    <br>
    <a href=form.php>بازگشت</a>
    [code/]
    من از این برنامه جائی دیگه استفاده کردم . و الانام داره کار میکنه .
    اما در مورد ذخیره تو database با توجه به اینکه خودت گفتی id اگه این برنامرو خوب بخونی همه چی رو متوجه میشی .

  3. #3
    سلام بر اقا مجید
    کار سختی نیست فقط کمی وقت لازم دارد
    البته طریقه سوال شما میزان آشنایی شما با php رو بیان نمی کنه که بتونم راهنایی زیادی بکنم ولی این رو بگم که ابتدا باید یک صفحه طراحی کنی شامل فیلد های ورود اطلاعات مثل:
    نام عکس
    نام ارسال کننده
    فیلد ارسال عکس
    و فیلد توضیحات در باره آن عکس
    قطعا وقتی این صفحه رو ساختی (مثلا با Dreamiver)که حتی می تونه htmlباشه در این صفحه باید یک فرم داشته باشی این فیلد های را که گفتم در بر بگیره(<form action="" method="get"></form>) و actione اون رو باید صفحه ای رو بزاری که کد های php تو در انجا قرار داره :
    البته این خودش یک کلاس اگه بدردت می خوره پیام بده که آموزش را ادامه بدم

  4. #4
    برای آپلود بد نیست:





    /*

    ---Description -----------------------------------------------------

    The Super Global Variable $_FILES is used in PHP 4.x.x.

    $_FILES['upload']['size'] ==> Get the Size of the File in Bytes.

    $_FILES['upload']['tmp_name'] ==> Returns the Temporary Name of the File.

    $_FILES['upload']['name'] ==> Returns the Actual Name of the File.

    $_FILES['upload']['type'] ==> Returns the Type of the File.

    So if I uploaded the file 'test.doc', the $_FILES['upload']['name']

    would be 'phptut.doc' and $_FILES['upload']['type'] would be 'application/msword'.

    ---------------------------------------------------------------------*/

    //************************************************** ********************//

    // $_FILES['filetoupload'] is the value of //

    // file field from the form. <input type="file" name="filetoupload"> //

    //************************************************** ********************//

    // this is the upload dir where files will go.

    //Don't remove the /

    //Chmod it (777)

    $upload_dir = "/var/www/html/admin/uploads/"; //change to whatever you want.

    //51200 bytes = 50KB

    $size_bytes = 1051200; //File Size in bytes (change this value to fit your need)

    $extlimit = "yes"; //Do you want to limit the extensions of files uploaded (yes/no)

    $limitedext = array(".gif"); //Extensions you want files uploaded limited to. also you can use: //array(".gif",".jpg",".jpeg",".png",".txt",".nfo"," .doc",".rtf",".htm",".dmg",".zip",".rar",".gz",".e xe");

    //check if the directory exists or not.

    if (!is_dir("$upload_dir")) {

    die ("The directory <b>($upload_dir)</b> doesn't exist");

    }

    //check if the directory is writable.

    if (!is_writeable("$upload_dir")){

    die ("The directory <b>($upload_dir)</b> is NOT writable, Please CHMOD (777)");

    }

    if($uploadform) // if you clicked the (Upload File) button. "If you submitted the form" then upload the file.

    {//begin of if($uploadform).



    //check if no file selected.

    if (!is_uploaded_file($_FILES['filetoupload']['tmp_name']))

    {

    echo "Error: Please select a file to upload!. <br>>>&nbsp;<a href=\"$_SERVER[PHP_SELF]\">back</a>";

    exit(); //exit the script and don't do anything else.

    }

    //Get the Size of the File

    $size = $_FILES['filetoupload']['size'];

    //Make sure that file size is correct

    if ($size > $size_bytes)

    {

    $kb = $size_bytes / 1024;

    echo "File Too Large. File must be <b>$kb</b> KB. <br>>>&nbsp;<a href=\"$_SERVER[PHP_SELF]\">back</a>";

    exit();

    }

    //check file extension

    $ext = strrchr($_FILES['filetoupload'][name],'.');

    if (($extlimit == "yes") && (!in_array($ext,$limitedext))) {

    echo("Wrong file extension. ");

    exit();

    }

    // $filename will hold the value of the file name submetted from the form.

    $filename = $_FILES['filetoupload']['name'];

    // Check if file is Already EXISTS.

    if(file_exists($upload_dir.$filename)){

    echo "Oops! The file named <b>$filename </b>already exists. <br> Deleted the file. Please go back and try again.<br>>>&nbsp;<a href=\"$_SERVER[PHP_SELF]\">back</a>";

    unlink($filename1);

    exit();

    }

    //Move the File to the Directory of your choice

    //move_uploaded_file('filename','destination') Moves afile to a new location.

    if (move_uploaded_file($_FILES['filetoupload']['tmp_name'],$upload_dir.$filename)) {

    //tell the user that the file has been uploaded and make him alink.

    echo "File ($filename) uploaded! <br>";



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

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