Jump to content

problam using $_POST


Accurax

Recommended Posts

I'm pretty sure im doing something pretty thick here, but could someone take a lok please?

heres my form to select the picture

[code]
<form enctype="multipart/form-data" method="POST" action="uploadprocess.php">

<input type="hidden" name="MAX_FILE_SIZE" value="15000000">

Choose file to send: <input type="file" name="filename"> and <input type="submit">

</form>[/code]and heres the php page that proccesses it:

[code]
<?php
$filepath = $_POST['filename'];
echo $filepath;

      $source = "pictures";
      move_uploaded_file($_FILES['filename']['tmp_name'],
              "../...../........./$source/".$_FILES['filename']['name']);


?>[/code]
The problem is that i cant seem to get the $_POST['filename'] variable to work, This variable should be the path to and filename of the uploaded picture, and the aim is really to get this value stored into my database for later use, for now i guess i just need to get the value passing properly, any idea's guys?
Link to comment
Share on other sites



Try this


if (isset($_POST['submit'])) {
 
//check for the file upload
if (is_uploaded_file ($_FILES['filename']['tmp_name'])) {
  if (move_uploaded_file ($_FILES['filename']['tmp_name'],"../pictures/{$_FILES['filename']['name']}")) {
   
    echo '<p>The file has been uploaded</p>';
} else {
  echo '<p><font color="red">the file did not upload</font></p>';
$image = '' ;
exit;
}

}
Link to comment
Share on other sites

[quote author=fearmyride link=topic=118170.msg482580#msg482580 date=1165838259]


Try this


if (isset($_POST['submit'])) {
 
//check for the file upload
if (is_uploaded_file ($_FILES['filename']['tmp_name'])) {
  if (move_uploaded_file ($_FILES['filename']['tmp_name'],"../pictures/{$_FILES['filename']['name']}")) {
   
    echo '<p>The file has been uploaded</p>';
} else {
  echo '<p><font color="red">the file did not upload</font></p>';
$image = '' ;
exit;
}

}
[/quote]


How do i get the path to the stored file out of this?...... i need to write this info into my database so i can call the image whenever i need
Link to comment
Share on other sites

make the variable before using move_upload_file.

[code=php:0]
$image_var = "../pictures/{$_FILES['filename']['name']}";
[/code]

then in move_uploaded_file:
[code=php:0]
move_uploaded_file ($_FILES['filename']['tmp_name'],$image_var)
[/code]

then in the success add the link to the database.
Link to comment
Share on other sites

None of that works guys.......... all i want to do is this

1) Move the uploaded file from the tmp folder to a permanent folder on my webserver...... Complete

2) Identify the precise path to this Moved file and store it in a a mysql database

I know that tis information is there.... i just cant get it out in a way that makes sense as to how im going to then write this into my database ......... what stores the path + file name .... i know the filename is stored in $_FILES['userfile']['name']; and as such ;

$filename = $_FILES['userfile']['name'];

should assign the file name to the variable $filename ..... i honestly couldnt tell you if it actually does, becauyse at the moment i cant even get the damnd thing to echo out correctly , and whilst i do really, honestly truly appreciate your posts, i am in fact confused as to how they address this issue.

Please can anyone actually explain how i do this..... im about to throw things around, and my cat looks terrified :p
Link to comment
Share on other sites

[quote author=ProjectFear link=topic=118170.msg482606#msg482606 date=1165840307]
why not before, like i suggested? :P
oh and just so you no. your code will throw an error. you didnt close the " and you can have arrays in a normal string. wrap it in {}. :P
[/quote]

before after tomorrow :) good point about using {} it's typo that will create an error
Link to comment
Share on other sites

Im trying this.... basically my theory is that if i can get a variable to echo what i want, then i should then be able to simply slap that variable in my database and voilla.

<?php
$filepath = "/pictures/".$_FILES['filename'];
echo $filepath;

      $source = "pictures";
      move_uploaded_file($_FILES['filename']['tmp_name'],
              "../webserver/mysite/$source/".$_FILES['filename']['name']);


?>

The file uploads without a problem .... but the echo statement gives me the following;

/pictures/Array

Which is not what i want .........  :(
Link to comment
Share on other sites

If you're only uploading one file at a time, then surely this will work?

[code]<?php
$filepath = "/pictures/".$_FILES['filename']['name'];
echo $filepath;

      $source = "pictures";
      move_uploaded_file($_FILES['filename']['tmp_name'],
              "../webserver/mysite/$source/".$_FILES['filename']['name']);


?>[/code]

Regards
Huggie
Link to comment
Share on other sites

I now feel like a right muppet....... i had:

$filepath = "/pictures/".$_FILES['filename'];

and i needed:

$filepath = "/pictures/".$_FILES['filename']['name'];

i think im going to go and cry in the corner for a while......... thanks for all the help guys ........  :)
Link to comment
Share on other sites

alright so you are doing what i or fearmyride suggested by making a variable with the path and the $_FILES['userfile']['name']. that should make a variable wiht a link like:
[code]../images/users/myimage.jpg[/code]

which you could then insert into the database. but your saying its not working.
well. before the if(move_upload_file... blah blah blah make the variable like is suggested.
then immediatly below it echo it out:

[code=php:0]echo $var;[/code]
then exit it.
[code=php:0]exit();[/code]

that should echo out the file name. if nothing is happening post it here... :)
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.