Page 1 of 1

File Upload got me stumped !!!!

Posted: Thu Feb 17, 2005 2:47 pm
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

Posted: Thu Feb 17, 2005 3:22 pm
by feyd
echo $saveDirectory after setting it.

Posted: Thu Feb 17, 2005 4:48 pm
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

Posted: Thu Feb 17, 2005 6:44 pm
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.

Posted: Thu Feb 17, 2005 6:49 pm
by feyd
scrotaye's example used a dot, not a comma.

Posted: Thu Feb 17, 2005 6:50 pm
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.