File upload problem

Hey guys,
I just put my shopping cart online and can’t seem to get photos to upload. All of the product details are showing so its not an issue with the $_POST superglobal, its some kind of strange filepath thing. All tested locally using localhost and working fine. Any ideas?

// Parse the form data and add inventory item to the system
if (isset($_POST['product_name'])) {
	$pid = mysql_real_escape_string($_POST['thisID']);
    $product_name = mysql_real_escape_string($_POST['product_name']);
	$price = mysql_real_escape_string($_POST['price']);
	$category = mysql_real_escape_string($_POST['category']);
	$subcategory = mysql_real_escape_string($_POST['subcategory']);
	$details = mysql_real_escape_string($_POST['details']);
	// See if that product name is an identical match to another product in the system - uses UPDATE to replace rather than append
	$sql = mysql_query("UPDATE products SET product_name='$product_name', price='$price', details='$details', category='$category', subcategory='$subcategory' WHERE id='$pid'");
	if ($_FILES['fileField']['tmp_name'] != "") { //give them the choice to replace picture or not bother
	    // Place image in the folder 
	    $newname = "$pid.jpg";
	    move_uploaded_file($_FILES['fileField']['tmp_name'], "../inventory_images/$newname");
	header("location: inventory_list.php"); 

button is labelled:

<input type=“file” name=“fileField” id=“fileField” />[QUOTE][/QUOTE]

I’ve had similar with move_uploaded_file… it’s a function I absolutely hate with a passion.

On Windows (which I use locally to develop) it works fine. Upload to a linux server and suddenly it wants the complete file path from the root of the disk.

It’s a pain but I think… thats given you enough to look at. Remember, using that script tester I gave you earlier you can do diagnostics… EG to see if a filepath exists and scan a directory to check its got what it should have in it etc. You should be able to determine if the server likes relative or full filepaths at least :wink:

My thoughts exactly but I checked the php.ini file on my hosting control panel and it says uploads: yes , is that what does it? Otherwise, the documentation is just realy poor, will have to read thoroughly 2morro. Thanks anyway webgypsy

Linux servers are also case sensitive too which I always forget, thanks both food for thought, anyway I have been coding for 12hours straight so gd nite to u both :wink:

I’ve never used a host yet that has uploads disabled. Like I said, you need to investigate the file paths on this one as I’m almost certain its that. As I said, Windows > Linux migrations has always given me hell with this function.

Seriously, I know its a basic looking script I gave you earlier but by god its useful and powerful when used correctly - trust me I’ve debugged the undebuggable with it with some very inventive thinking… :wink:

Just another thought, I’ve just remembered that I’ve got around problems like this in the past by using getcwd();


$Path = getcwd .'/files/';

getcwd() just returns the full path to the current working directory where the script is.

Yup, another victim of that here too;)

What is the number stored in $_FILES[‘fileField’][‘error’]

Hey there’s no error,
The page displays just fine but with no pictures.

<< Jumps up and down shouting FILE PATHS :stuck_out_tongue:

Oh almost forgot… Morning! :smiley:

Hey ,
Thanks guys just fixed it , needed an absolute path. :slight_smile:

Gd morning to u too and welcome to another day of coding fun :wink:

Who da man?

eeek sorry was about to say you but then I realized that I havent actually fixed the problem, there was a photo which I had uploaded for troubleshooting and somehow it got displayed. full filepath def doesnt work - the code is now:

move_uploaded_file($_FILES[‘fileField’][‘tmp_name’], "$newname
doesn’t work :frowning:

http dosen’t support uploading files unless done through post. Php can’t move anything via http unless using curl or ftp etc.

You need to use the SERVER file path - eg: var/usrs/home/<>/public_html/images or whatever yours is (use php’s phpinfo() function to find this sort of thing - IE in my script i gave you)

Ah right, thanks very much, haven’t ever uploaded anything with php before so I’ve just learnt something new. I’ll give it a go and let you know how I get on.
thanks again tangoforce

No worries :wink:

Seriously, use that script I gave you (add some password protection) and type into the box:


Scroll down to the section that says PHP variables and look for one called