...

View Full Version : move_uploaded_file not working properly... please anyone tell me why it is not workg?



karthikm19
09-18-2009, 10:57 PM
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

Fumigator
09-18-2009, 11:03 PM
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/function.move-uploaded-file.php

http://us2.php.net/manual/en/features.file-upload.errors.php



error_reporting(E_ALL);
ini_set("display_errors", 1);

karthikm19
09-18-2009, 11:07 PM
thank you... i m going to use this...

cheers

karthikm19
09-18-2009, 11:16 PM
i think there is no error in this code.. it is working in one server.. same code is not working in another server..

MattF
09-18-2009, 11:24 PM
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.

karthikm19
09-18-2009, 11:26 PM
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

MattF
09-18-2009, 11:29 PM
Do the relevant directories exist? Are permissions correct? Are the paths correct?

MattF
09-18-2009, 11:31 PM
Also, add:



error_reporting(E_ALL);


at the top of your script, just after the opening <?php tag.

karthikm19
09-18-2009, 11:34 PM
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

Fumigator
09-19-2009, 01:09 AM
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.

karthikm19
09-19-2009, 01:14 AM
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

Fumigator
09-19-2009, 01:25 AM
Can we see your updated code with all of the additions I just mentioned?

karthikm19
09-19-2009, 01:35 AM
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

}

}

?>

MattF
09-19-2009, 03:22 AM
Unless I've got ballbearings for eyes today, you've implemented none of Fumigator's suggestions in your code.

Sam STrawbridge
05-18-2010, 06:05 PM
Have you checked that Register Globals is on? That was the problem for me, stupid really but just one of those things

Fou-Lu
05-18-2010, 07:40 PM
Have you checked that Register Globals is on? That was the problem for me, stupid really but just one of those things

As for 4.2 register globals should never be used (superglobal replacements), has been officially deprecated as of 5.3, and should be removed as of 6.0. Therefore, you should go out of your way to have zero reliance on register globals. It also has no effect on the files superglobal.

You are not doing anything to verify that the files were successfully uploaded. Checking the name is not sufficient. Sounds to me like none of these are uploaded correct? Choose any of them and run a var_dump($_FILES['image1']); for example.
Put this directly after this:


$ext_image1 = "";
$ext_image2 = "";
$ext_image3 = "";
$ext_bgimage1 = "";
$ext_bgimage2 = "";
$ext_bgimage3 = "";


Post those results, and we'll go from there.


Actually, now that I think of this, I believe the _FILES does actually get extracted from the register globals.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum