Jump to content

The mystery of the disappearing variables!


ginadas

Recommended Posts

Hi all,

 

I was hoping someone coulding she a bit of light on some strangely disappearing variables!

I am using php to recieved and process uploaded files into local folders for a dynamic gallery site. the picture information & categorisation, i intend to store in a mysql database and i'm using flex from my front end - which will process xml generated by php to sort out various albums.

 

my first approach was to try and create seperate folders for each album upload. here is the script:

 

<?php
     
mkdir("program_code/" . $_REQUEST['albumname'] . "/");
$target_path = "root/program_code/" . $_REQUEST['albumname'];
//$target_path = $target_path 
$target_path = $target_path . "/";
$target_path = $target_path . basename( $_FILES['Filedata']['name']); 

move_uploaded_file($_FILES['Filedata']['tmp_name'], $target_path);

?>

 

the $_REQUEST['username'] passes in successfully my problem is - the files save in the program_code/ directory, not the newly created directory from the albumname variable - it's like php chooses to ignore it. i understand move_uploaded_file on windows acts on the root directory, so i tried putting in a literal path like root/program_code/pics whilst passing in pics as a request parameter - surely enough, the folder is created and images upload to the pic directory - php just refusess to see it or process it in time when passed in as a reuest parameter for the move_uploaded_file method

 

 

so i tried a different approach - creating unique hashed filenames for each uploaded file and storing the names into a newly created mysql table which takes the albumname request parameter as it's name. here is the code:

 

<?php
     
include("config.inc.php");

$uploaddir = "images/";
$file = $_FILES['Filedata'];
$name = sha1_file($file['tmp_name']);
$pathInfo = pathinfo($file['name']);
$name .= '.'.$pathInfo['extension'];

move_uploaded_file($file['tmp_name'], $uploaddir.$name);

    
$q = <<<CREATE
create table $_REQUEST[username]( 
photo_id bigint(20) unsigned NOT NULL auto_increment, 
photo_filename varchar(80),
photo_category bigint(20) unsigned NOT NULL default '0', 
PRIMARY KEY  (photo_id), 
KEY photo_id (photo_id) 
) TYPE=MyISAM;
CREATE;
mysql_query($q);


$nam = sha1_file($file['tmp_name']);

$p = <<<CREATE
insert into $_REQUEST[username] (photo_filename) values ("$name");
CREATE;

mysql_query($p);
?>

 

 

the files save with long and unique filenames (eg image8b6f73f2b35b997af7633116bf8f46ab026e0c8d.jpg) - but when i pass the name variable into mysql - it merely saves as "." - it's wildly infuriating! because i know the variable is there but it simply will not carry thought/transmit into the mysql table!

 

so i'm truly stuck now...! if any of you php gurus can help out with what i'm sure is embarrasingly obvious i'd be so thankful, needless to say, i've clumsily googled this to death to no avail

 

cheers,

 

gina

 

 

ps - my config is using WAMP server on a win xp machine

Link to comment
Share on other sites

hi PhREEEk ,

 

just gave that a go, i've tried a bunch of variation that all end with that bloody dot - in the original declaration, $name .= '.'.$pathInfo['extension']; , its the '.' that seems to be producing the dot - because if i produce a new variable using the

sha1_file function - the mysql field returns empty - so the variable itself seems t be empty - but i know its working at the start because my files are getting named & saved correctly

 

its mind-boggling really, do you have any idea about my first one too - cos once again, it's a sort of variable-not-speaking-up type thing

 

cheers for your help  :)

Link to comment
Share on other sites

Dump the variable right before the insert, and let's see what it says...

 

var_dump($name);
$p = "INSERT INTO $_REQUEST[username] (`photo_filename`) values ('$name')";

 

If you get . as the var_dump, then you need to work backwards to find the error. If var_dump returns what you expect, and it still isn't inserting 1 line later, then there may be a problem with the field you are trying to store it in (although it appears it is VARCHAR (80), which should work....

 

: shrug :

 

Well, got to get some other stuff done... so best of luck with it!

 

PhREEEk

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.