By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,890 Members | 1,039 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,890 IT Pros & Developers. It's quick & easy.

upload files frustration

P: 4
Hi all
I am trying to upload images to a remote server and it fails all the time.
My $_FILES array looks as follows
[php]
[thumbnail] => Array
(
[name] => 01.jpg
[type] => image/jpeg
[tmp_name] => d:\upload_tmp\php5F90.tmp
[error] => 0
[size] => 1268
)

[bigPic] => Array
(
[name] => 01.jpg
[type] => image/jpeg
[tmp_name] => d:\upload_tmp\php5F91.tmp
[error] => 0
[size] => 1268
)
[/php]
It contains both pics I want to load and it seems Valid(no error flag)

The upload file is called "http://www.o-shan.com/DBImages/eYkrAkfFHFyNybzQ8Nfn.jpg"

meaning I use the command
[php]if (move_uploaded_file($_FILES[$fieldName]['tmp_name'], $uploadfile))[/php]
Sending the tempfile to the mentioned location

The condition statement always fails!!!!
(The permissions are fine)
Any ideas?
How can I debug it?
Tnx
Danny
Feb 24 '08 #1
Share this Question
Share on Google+
7 Replies


Markus
Expert 5K+
P: 6,050
Hi all
I am trying to upload images to a remote server and it fails all the time.
My $_FILES array looks as follows
[php]
[thumbnail] => Array
(
[name] => 01.jpg
[type] => image/jpeg
[tmp_name] => d:\upload_tmp\php5F90.tmp
[error] => 0
[size] => 1268
)

[bigPic] => Array
(
[name] => 01.jpg
[type] => image/jpeg
[tmp_name] => d:\upload_tmp\php5F91.tmp
[error] => 0
[size] => 1268
)
[/php]
It contains both pics I want to load and it seems Valid(no error flag)

The upload file is called "http://www.o-shan.com/DBImages/eYkrAkfFHFyNybzQ8Nfn.jpg"

meaning I use the command
[php]if (move_uploaded_file($_FILES[$fieldName]['tmp_name'], $uploadfile))[/php]
Sending the tempfile to the mentioned location

The condition statement always fails!!!!
(The permissions are fine)
Any ideas?
How can I debug it?
Tnx
Danny
It'd be nice to see the rest of your code...
We aren't magicians.
Feb 24 '08 #2

P: 4
It'd be nice to see the rest of your code...
We aren't magicians.
Sure mate

The following is the code for extracting the data from the file control:
($data['name'] is the text in the control itself)

function getData($data,$fieldName)
{
global $uploaddir,$db;

//Get data from the file control
$imageName = $data[name];

//a new image is set and waiting in the file control
if ($imageName)
{
//get the image type
$arr = explode('.',$imageName);
$imageType = $arr[count($arr)-1];

//create a file name
$fileName = generateRandomName(20).'.'.$imageType;

//create the file name with full path
$uploadfile = $uploaddir . $fileName;

echo is_uploaded_file($_FILES[$fieldName]['tmp_name']).'<br>';
print_r($_FILES);
echo "<br>$uploadfile";
//move file to new location
if (move_uploaded_file($_FILES[$fieldName]['tmp_name'], $uploadfile))
{
echo "File is valid, and was successfully uploaded.\n";

//insert file data to images table
$fieldNameArr = array();
$fieldValsArr = array();
array_push($fieldNameArr,'fileName');
array_push($fieldValsArr,'"'.$fileName.'"');

$db->insert('images',$fieldNameArr,$fieldValsArr);
}

else
{
echo "Possible file upload attack!\n";
return NULL;
}
return '"'.$fileName.'"';
}
else
return NULL;
}
}

Any ideas?
Feb 24 '08 #3

Markus
Expert 5K+
P: 6,050
Adding code tags (please remember to use these...)
[php]
function getData($data,$fieldName)
{
global $uploaddir,$db;

//Get data from the file control
$imageName = $data[name];

//a new image is set and waiting in the file control
if ($imageName)
{
//get the image type
$arr = explode('.',$imageName);
$imageType = $arr[count($arr)-1];

//create a file name
$fileName = generateRandomName(20).'.'.$imageType;

//create the file name with full path
$uploadfile = $uploaddir . $fileName;

echo is_uploaded_file($_FILES[$fieldName]['tmp_name']).'<br>';
print_r($_FILES);
echo "<br>$uploadfile";
//move file to new location
if (move_uploaded_file($_FILES[$fieldName]['tmp_name'], $uploadfile))
{
echo "File is valid, and was successfully uploaded.\n";

//insert file data to images table
$fieldNameArr = array();
$fieldValsArr = array();
array_push($fieldNameArr,'fileName');
array_push($fieldValsArr,'"'.$fileName.'"');

$db->insert('images',$fieldNameArr,$fieldValsArr);
}

else
{
echo "Possible file upload attack!\n";
return NULL;
}
return '"'.$fileName.'"';
}
else
return NULL;
}
}
[/php]
Now i shall have a look through.
Feb 24 '08 #4

Markus
Expert 5K+
P: 6,050
Can you re-explain the problem?
Try and be concise and precise.

Also, do you get any errors?
Feb 24 '08 #5

P: 4
Thanks for the patience
My problem is that I don't have any indication for any problem on script.

I get a temporary file path on the "$_FILES" array.

Still the move_uploaded_file command fails - It returns False and does not upload the files to my desired directory.

If I had any error notification I could try and fix it.

The above code should work. Has anyone encountered similar problems and managed to solve them?
Thanks
Danny
Feb 25 '08 #6

P: 4
Hi
I have solved it but in a very wiered way.
I am using relative path - ../DBImages instead of a standard url.
It works and can suffice but if you have a clue of what is going on I would be happy to hear (I think there is a way of configuring the path on server)
Yours
Danny
Feb 25 '08 #7

Markus
Expert 5K+
P: 6,050
You'd be able to upload files to any server if you used direct urls!
(or atleast try :P )
Feb 25 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.