please help me on this code

Discussion in 'PHP' started by mirosoft1, Mar 2, 2008.

  1. #1
    this code is to add image but it didnot work can any one help me please on this code


    when i run this code it gives me all time message "error"

    <?

    $file_type =array('.gif', '.jpg', '.jpeg', '.Bmp');
    $size =600000000000;
    $path ="http://mysite/newsss/admin/up/up"; // the place where i put on it the image
    $ext =strrchr($file_name,".");
    $file_name ="news_".rand().$ext;
    $url_up="http://mysite/newsss/admin/up/up";//

    if ($file_name =="")
    {
    print "choose the image";
    }
    else
    {
    if(file_exists($path."/".$file_name))
    {
    print "this image is exist";
    }
    else
    {
    if($file_size > $size)
    {
    print "the size too large";
    }
    else
    {
    if(!in_array($ext , $file_type))
    {
    print "error";
    }
    else
    {
    ( move_uploaded_file($_POST[file] ,$path."/".$file_name)) or print "error";
    print "<center><font size='1' face='MS Sans Serif'>ok it upload<br>admin/up/up/$file_name<br>

    </font><palign='center'>
    <p align='center'><img border='0' src='up/$file_name'width='120' height='120'></p>

    ";
    }

    }
    }
    }

    ?>



    and on the other page i make a form and file browse to choose the image

    <input type="file" name="file" size="21" >
     
    mirosoft1, Mar 2, 2008 IP
  2. Georgsius

    Georgsius Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try this

    <?

    $allowed_extensions = array("gif", "jpg", "png", "jpe", "jpeg");
    $size =600000000000;
    $path ="http://mysite/newsss/admin/up/up"; // the place where i put on it the image
    $ext =strrchr($file_name,".");
    $img_name_arr = explode(".",$file_name);
    $type = end($img_name_arr);
    $file_name ="news_".rand().$ext;
    $url_up="http://mysite/newsss/admin/up/up";//

    if ($file_name =="")
    {
    print "choose the image";
    }
    else
    {
    if(file_exists($path."/".$file_name))
    {
    print "this image is exist";
    }
    else
    {
    if($file_size > $size)
    {
    print "the size too large";
    }
    else
    {
    if(!(in_array($type, $allowed_extensions) or in_array(strtolower($type), $allowed_extensions)) )
    {
    print "error";
    }
    else
    {
    ( move_uploaded_file($_POST[file] ,$path."/".$file_name)) or print "error";
    print "<center><font size='1' face='MS Sans Serif'>ok it upload<br>admin/up/up/$file_name<br>

    </font><palign='center'>
    <p align='center'><img border='0' src='up/$file_name'width='120' height='120'></p>

    ";
    }

    }
    }
    }

    ?>
     
    Georgsius, Mar 3, 2008 IP
  3. mirosoft1

    mirosoft1 Well-Known Member

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #3
    it gives me message "error" :(
     
    mirosoft1, Mar 3, 2008 IP
  4. Georgsius

    Georgsius Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You sure that you upload image?
    What kind of files you need to upload?
     
    Georgsius, Mar 3, 2008 IP
  5. mirosoft1

    mirosoft1 Well-Known Member

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #5
    i need to upload images and this code make that but there is something missing or wrong i donot know why this code not working???? please help me
     
    mirosoft1, Mar 3, 2008 IP