File Upload got me stumped !!!!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gand
Forum Newbie
Posts: 2
Joined: Thu Feb 17, 2005 2:36 pm

File Upload got me stumped !!!!

Post by gand »

Any help on this would be great.

I am trying to upload files into directories based on a parameter passed through a URL. I have created a RS for this.

If i use the line commented out, it uplaods fine, but when i try to use the recordset bID as the folder name, it always uploads to the root.

Code: Select all

//Created Recordset
mysql_select_db($database_band, $band);
$query_rsControl = sprintf("SELECT band.bID, band.bName, band.bType, band.bLevel, band.style, band.userID, users.sessionid FROM users INNER JOIN band ON users.userID = band.userID WHERE (((users.sessionid)='%s')) AND band.bID = '%s'", $colname_rsControl,$colname1_rsControl);
$rsControl = mysql_query($query_rsControl, $band) or die(mysql_error());
$row_rsControl = mysql_fetch_assoc($rsControl);
$totalRows_rsControl = mysql_num_rows($rsControl);


<?php 
//This is the code
if (!empty($_FILES&#1111;'ourFile']&#1111;'name'])) &#123;

//This line will upload fine into the correct folder.    
//$saveDirectory = 'bands/62/';

$saveDirectory = 'bands/'.$row_rsControl&#1111;bID].'/';

$tempName = $_FILES&#1111;'ourFile']&#1111;'tmp_name'];
    $fileName = $_FILES&#1111;'ourFile']&#1111;'name'];

    if (move_uploaded_file($tempName, $saveDirectory . $fileName)) &#123;
        echo 'File Successfully Uploaded!';
    &#125; else &#123;
        echo 'There was an error whilst uploading the file.';
    &#125;
&#125; else &#123;
    ?>

feyd | Please post using formatting tags
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

echo $saveDirectory after setting it.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

This is just a guess here, but you have single quotes inside of single quotes in your save directory.

Try this

Code: Select all

$saveDirectory = "bands/".$row_rsControl&#1111;bID]."/";
I'm not sure if it'd make a difference.

Also, make sure you have that folder's permissions set to allow file uploads, and make sure the directory exists.

Also, this looks like it could be a problem.

Code: Select all

if (move_uploaded_file($tempName, $saveDirectory . $fileName)) &#123;
are you sure you want $saveDirectory . $filename? Maybe you want $saveDirectory/$filename or $saveDirectory, $filename
gand
Forum Newbie
Posts: 2
Joined: Thu Feb 17, 2005 2:36 pm

Post by gand »

Hi
I changed the first line and tried the alternative method you suggested

$saveDirectory, $filename gave this error
Warning: Wrong parameter count for move_uploaded_file() in c:\program files\apache group\apache\htdocs\caol\upload.php

$saveDirectory/$filename
did not produce any errors but it did not upload the file.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

scrotaye's example used a dot, not a comma.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Before this line:
if (move_uploaded_file($tempName, $saveDirectory . $fileName)) {

Do:

Code: Select all

echo 'Moving uploaded file using:<br />';
echo 'tempName = '.$tempName.'<br />';
echo 'saveDirectory = '.$saveDirectory.'<br />';
echo 'fileName = '.$fileName.'<br />';
One or more of those vars is probably empty/not set.
Post Reply