Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    New Coder
    Join Date
    Sep 2009
    Location
    Bangalore , India
    Posts
    10
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Question move_uploaded_file not working properly... please anyone tell me why it is not workg?

    Here is my code.. which is working well in one server.. but when i m uploading into another server.. then it is not working.. i dont know why it is not working..
    please see my code below..

    //PHP Code
    $path_image1 = "../images/product images/" . $_FILES['image1']['name'];
    move_uploaded_file($_FILES["image1"]["tmp_name"], $path_image1);

    //Form
    <form id="register" name="register" action="#" method="post" enctype="multipart/form-data">
    <input name="image1" type="file" />
    </form>

    thanks,
    N.Karthik
    karthikzmsg@gmail.com
    Last edited by karthikm19; 09-18-2009 at 09:59 PM. Reason: added some info

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    You need to check the return value of the function, as well as the error code. Make sure your error reporting is turned on.

    http://us2.php.net/manual/en/functio...oaded-file.php

    http://us2.php.net/manual/en/feature...oad.errors.php

    PHP Code:
    error_reporting(E_ALL);
    ini_set("display_errors"1); 

  • #3
    New Coder
    Join Date
    Sep 2009
    Location
    Bangalore , India
    Posts
    10
    Thanks
    0
    Thanked 2 Times in 2 Posts
    thank you... i m going to use this...

    cheers

  • #4
    New Coder
    Join Date
    Sep 2009
    Location
    Bangalore , India
    Posts
    10
    Thanks
    0
    Thanked 2 Times in 2 Posts
    i think there is no error in this code.. it is working in one server.. same code is not working in another server..

  • #5
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Quote Originally Posted by karthikm19 View Post
    i think there is no error in this code.. it is working in one server.. same code is not working in another server..
    There is obviously some error then. As pointed out above, find out what the error encountered is.

  • #6
    New Coder
    Join Date
    Sep 2009
    Location
    Bangalore , India
    Posts
    10
    Thanks
    0
    Thanked 2 Times in 2 Posts
    hi MattF...

    i have tried the code which is above mentioned... but no error is printed on my screen while executing that file...

    now what i hav to do now???

    thanks

  • #7
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Do the relevant directories exist? Are permissions correct? Are the paths correct?

  • #8
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Also, add:

    Code:
    error_reporting(E_ALL);
    at the top of your script, just after the opening <?php tag.

  • #9
    New Coder
    Join Date
    Sep 2009
    Location
    Bangalore , India
    Posts
    10
    Thanks
    0
    Thanked 2 Times in 2 Posts
    i am creating the directories dynamically before doing "move_uploaded_file"... i m creating directory using mkdir() function with 0777 permissions..

    when i open the folder in FileZilla, it is showing the file permissions properly like "drwxrwxrwx"

    after creating folder next step in my code is move_uploaded_file function with the same folder i m creating.. but only this not working...

    thanks

  • #10
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    So you added code to check not only the returning value of the move_uploaded_file() function but also to evaluate the error message? Let's see.

  • #11
    New Coder
    Join Date
    Sep 2009
    Location
    Bangalore , India
    Posts
    10
    Thanks
    0
    Thanked 2 Times in 2 Posts
    i have checked in all the possibilities.. i think the problem is in the "OWNER/GROUP" while creating directory...

    Can you please tell me how to set Owner/Group while creating folders..

    thanks

  • #12
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Can we see your updated code with all of the additions I just mentioned?

  • #13
    New Coder
    Join Date
    Sep 2009
    Location
    Bangalore , India
    Posts
    10
    Thanks
    0
    Thanked 2 Times in 2 Posts
    ya sure..

    <?php
    error_reporting(E_ALL);
    session_start();

    if($_SESSION['adminLogin']=="")
    {
    ?>
    <script> window.location="index.php";</script>
    <?php }
    include("config/db_connect.php");
    include_once("fckeditor/fckeditor.php");

    $sub_cat=$_REQUEST['subcat'];

    if($_SERVER['REQUEST_METHOD']=='POST')
    {


    $ext_image1 = "";
    $ext_image2 = "";
    $ext_image3 = "";
    $ext_bgimage1 = "";
    $ext_bgimage2 = "";
    $ext_bgimage3 = "";
    if($_FILES["image1"]["name"] != "" && $_FILES["image2"]["name"] != "" && $_FILES["image3"]["name"] != "" && $_FILES["bg_image1"]["name"] != "" && $_FILES["bg_image2"]["name"] != "" && $_FILES["bg_image3"]["name"] != "" )
    {
    $dir = "../images/product images/" . $_REQUEST['prod_code'];

    mkdir($dir,0755);
    chmod($dir,0755);
    $file_name1 = $_FILES["image1"]["name"];
    $ext1 = explode(".",$file_name1);

    $file_name2 = $_FILES["image2"]["name"];
    $ext2= explode(".",$file_name2);

    $file_name3 = $_FILES["image3"]["name"];
    $ext3 = explode(".",$file_name3);

    $file_name4 = $_FILES["bg_image1"]["name"];
    $ext4 = explode(".",$file_name4);

    $file_name5 = $_FILES["bg_image2"]["name"];
    $ext5 = explode(".",$file_name5);

    $file_name6 = $_FILES["bg_image3"]["name"];
    $ext6 = explode(".",$file_name6);

    $path_image1 = "../images/product images/" . $_REQUEST['prod_code'] . "/" . $_REQUEST['prod_code'] . "." . $ext1[1];
    $path_image2 = "../images/product images/" . $_REQUEST['prod_code'] . "/" . $_REQUEST['prod_code'] . "_b." . $ext2[1];
    $path_image3 = "../images/product images/" . $_REQUEST['prod_code'] . "/" . $_REQUEST['prod_code'] . "_s." . $ext3[1];

    $path_bg1 = "../images/product images/" . $_REQUEST['prod_code'] . "/" . $_REQUEST['prod_code'] . "_bg." . $ext4[1];
    $path_bg2 = "../images/product images/" . $_REQUEST['prod_code'] . "/" . $_REQUEST['prod_code'] . "_bg_b." . $ext5[1];
    $path_bg3 = "../images/product images/" . $_REQUEST['prod_code'] . "/" . $_REQUEST['prod_code'] . "_bg_s." . $ext6[1];



    //echo $_FILES["image1"]["tmp_name"]; exit;



    $copied = copy($_FILES["image1"]["tmp_name"], $path_image1);


    move_uploaded_file($_FILES["image1"]["tmp_name"], $path_image1);
    move_uploaded_file($_FILES["image2"]["tmp_name"], $path_image2);
    move_uploaded_file($_FILES["image3"]["tmp_name"], $path_image3);
    move_uploaded_file($_FILES["bg_image1"]["tmp_name"], $path_bg1);
    move_uploaded_file($_FILES["bg_image2"]["tmp_name"], $path_bg2);
    move_uploaded_file($_FILES["bg_image3"]["tmp_name"], $path_bg3);


    }


    if($_REQUEST['mode']=='add')
    {
    mysql_query("insert into tbl_product values('null','".$_REQUEST['prod_name']."','".$_REQUEST['prod_code']."','".$_REQUEST['category_name']."', '".$_REQUEST['subcategory_name']."', '" . join(",",$_POST["avail_type"]) . "','".$_REQUEST['price']."','".$_POST['FCKeditor1']."', '" . $ext1[1] . "','" . $ext2[1] . "','" . $ext3[1] . "','" . $ext4[1] . "','" . $ext5[1] . "','" . $ext5[1] . "') ");
    }

    if($_REQUEST['mode']=='edit')
    {


    /*echo "update tbl_product set product_name='".$_REQUEST['prod_name']."', product_code='".$_REQUEST['prod_code']."', product_type='".$_REQUEST['prod_type']."', category_name='".$_REQUEST['category_name']."',price='".$_REQUEST['price']."',product_desc='". addslashes($_POST['FCKeditor1'])."' where id='".$_REQUEST['id']."'";
    if($ext_front != "")
    echo "update tbl_product set product_thumbnail='$ext_front' where id='".$_REQUEST['id']."'";
    if($ext_bg != "")
    echo "update tbl_product set product_image='$ext_bg' where id='".$_REQUEST['id']."'";
    */

    mysql_query("update tbl_product set product_name='".$_REQUEST['prod_name']."', product_code='".$_REQUEST['prod_code']."', category_name='".$_REQUEST['category_name']."',sub_category='".$_REQUEST['subcategory_name']."',color='" . join(",",$_POST["avail_type"]) . "',price='".$_REQUEST['price']."',product_desc='". addslashes($_POST['FCKeditor1'])."' where id='".$_REQUEST['id']."'");
    if($ext_image1 != "")
    mysql_query("update tbl_product set image1='$ext_image1' where id='".$_REQUEST['id']."'");
    if($ext_image2 != "")
    mysql_query("update tbl_product set image2='$ext_image2' where id='".$_REQUEST['id']."'");
    if($ext_image3 != "")
    mysql_query("update tbl_product set image3='$ext_image3' where id='".$_REQUEST['id']."'");
    if($ext_bgimage1 != "")
    mysql_query("update tbl_product set bg_image1='$ext_bgimage1' where id='".$_REQUEST['id']."'");
    if($ext_bgimage2 != "")
    mysql_query("update tbl_product set bg_image2='$ext_bgimage2' where id='".$_REQUEST['id']."'");
    if($ext_bgimage3 != "")
    mysql_query("update tbl_product set bg_image3='$ext_bgimage3' where id='".$_REQUEST['id']."'");

    ?>
    <script>
    window.location="view_product.php?edit_msg=msg01"
    </script>
    <?php

    }

    }

    ?>

  • #14
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Unless I've got ballbearings for eyes today, you've implemented none of Fumigator's suggestions in your code.

  • #15
    New to the CF scene
    Join Date
    May 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Have you checked that Register Globals is on? That was the problem for me, stupid really but just one of those things


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •