PDA

View Full Version : uploading image question



collint20
08-07-2007, 09:05 PM
I feel my problem is with the path, could you verifys this for me.

Here is my code:

if ($pic_file_size >250000){$msg=$msg."file too big.<BR>";
$file_upload="false";}

if (!($pic_file_type =="image/pjpeg" OR $pic_file_type=="image/gif")){$msg=$msg."file must be of JPG or GIF.";
$file_upload="false";}

$add = $_SERVER['DOCUMENT_ROOT'].'/BSimages/'.$pic_file_name;

if(move_uploaded_file ($pic_file, $add)){
}else{echo "Failed to upload file Contact Site admin to fix the problem";}

I have verified that $pic_file exists (ok)
I have set chmod permissions to 777 on the BSimages folder (ok)
This script is running in the folder 'bstore' (path:/public_html/bstore/BSimages/)

One thing interesting is that
when I echo $pic_file it returns the statement 'array'
when I echo $pic_file_name nothing returns

Thank you,
Collin

collint20
08-07-2007, 10:02 PM
side note:

My globals are not set to 'on' - because I have read it isn't a safe practice.

So, when I pass variables via a form to another page, I have to use this:

import_request_variables(gp, "formval_");

to retrieve the variables.

Will, this make any difference in my files being uploaded?

collint20
08-07-2007, 10:15 PM
yes, my form page is using:

<FORM ENCTYPE="multipart/form-data" ACTION="_URL_" METHOD=POST>

MikeC
08-08-2007, 08:30 AM
I have no idea what you're asking for here, but are you making a simple uploader script and can't get it to upload to the specified directory or what exactly?

collint20
08-08-2007, 11:37 PM
sorry if my whole discription was vague.

Yes, I am trying to upload images to a folder hosted by hotmonster.com.

The script is really very simple, so there are not many areas I could go wrong. I debugged everyline in the script to make sure each line is working correctly.

My path even seems correct.

So, now I am guessing that the error comes from how I request the variables, with globals off, I am using -

import_request_variables(gp, "formval_");

When I echo the string: $pic_file - the echo returns 'array' statement
When I echo the string: $pic_file_name - echo returns nothing.

Thank you for your help

Seb
08-09-2007, 03:22 PM
You are not retrieving the variables from the form in a correct way. Your import_request_variables() does not retrieve the $_FILES array, which you need to use.

To get variables from a form use something like this:

<form action="URL" method="post" enctype="multipart/form-data">
<input type="text" name="test" value="atext" />
<input type="file" name="apicture" />
</form>


$test = $_POST['test'];
echo $test;

$pic = $_FILES['apicture'];
echo $pic['name'];

// the file array looks like this
// $_FILES[] = array('name', 'type', 'size', 'tmp_name', 'error');

Also you will need to use the $_FILES[x]['tmp_name'] as the first parameter in the move_uploaded_file() function, not the entire file array (that is what you're doing now).