Accurax Posted December 11, 2006 Share Posted December 11, 2006 Was having some problems getting this posted..... please find the question in the next post..... really appreciate any help on this guys Quote Link to comment https://forums.phpfreaks.com/topic/30219-problam-using-_post/ Share on other sites More sharing options...
Accurax Posted December 11, 2006 Author Share Posted December 11, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/30219-problam-using-_post/#findComment-138913 Share on other sites More sharing options...
Accurax Posted December 11, 2006 Author Share Posted December 11, 2006 <cut> Quote Link to comment https://forums.phpfreaks.com/topic/30219-problam-using-_post/#findComment-138914 Share on other sites More sharing options...
fearmyride Posted December 11, 2006 Share Posted December 11, 2006 Try thisif (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 Link to comment https://forums.phpfreaks.com/topic/30219-problam-using-_post/#findComment-138924 Share on other sites More sharing options...
JasonLewis Posted December 11, 2006 Share Posted December 11, 2006 wow whats with all the ../............../............................../ lol. that wouldnt do crap all. ../ would take you to the parent but i dont think ................./ does anything.but anyways. what fearmyride looks good for me. Quote Link to comment https://forums.phpfreaks.com/topic/30219-problam-using-_post/#findComment-138926 Share on other sites More sharing options...
fearmyride Posted December 11, 2006 Share Posted December 11, 2006 i think he used the dots instead of the folder name because you're right it will do nothing i believe Quote Link to comment https://forums.phpfreaks.com/topic/30219-problam-using-_post/#findComment-138931 Share on other sites More sharing options...
Accurax Posted December 11, 2006 Author Share Posted December 11, 2006 thats right, im over cautios about posting lol Quote Link to comment https://forums.phpfreaks.com/topic/30219-problam-using-_post/#findComment-138933 Share on other sites More sharing options...
Accurax Posted December 11, 2006 Author Share Posted December 11, 2006 [quote author=fearmyride link=topic=118170.msg482580#msg482580 date=1165838259]Try thisif (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 Quote Link to comment https://forums.phpfreaks.com/topic/30219-problam-using-_post/#findComment-138935 Share on other sites More sharing options...
Accurax Posted December 11, 2006 Author Share Posted December 11, 2006 my above script works perfectly... (ignoring security) .. all im trying to do is get the path to the moved file into a variable so i can put it in my database Quote Link to comment https://forums.phpfreaks.com/topic/30219-problam-using-_post/#findComment-138938 Share on other sites More sharing options...
JasonLewis Posted December 11, 2006 Share Posted December 11, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/30219-problam-using-_post/#findComment-138942 Share on other sites More sharing options...
fearmyride Posted December 11, 2006 Share Posted December 11, 2006 try making a $var like this after the file is uploaded :$var = "../foldername/$_FILES['filename']['name'];and then query the $var by inserting into the database Quote Link to comment https://forums.phpfreaks.com/topic/30219-problam-using-_post/#findComment-138945 Share on other sites More sharing options...
JasonLewis Posted December 11, 2006 Share Posted December 11, 2006 why not before, like i suggested? :Poh 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 Link to comment https://forums.phpfreaks.com/topic/30219-problam-using-_post/#findComment-138950 Share on other sites More sharing options...
Accurax Posted December 11, 2006 Author Share Posted December 11, 2006 None of that works guys.......... all i want to do is this1) Move the uploaded file from the tmp folder to a permanent folder on my webserver...... Complete2) Identify the precise path to this Moved file and store it in a a mysql databaseI 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 Quote Link to comment https://forums.phpfreaks.com/topic/30219-problam-using-_post/#findComment-138953 Share on other sites More sharing options...
fearmyride Posted December 11, 2006 Share Posted December 11, 2006 [quote author=ProjectFear link=topic=118170.msg482606#msg482606 date=1165840307]why not before, like i suggested? :Poh 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 Quote Link to comment https://forums.phpfreaks.com/topic/30219-problam-using-_post/#findComment-138956 Share on other sites More sharing options...
Accurax Posted December 11, 2006 Author Share Posted December 11, 2006 Can someone please help me here Quote Link to comment https://forums.phpfreaks.com/topic/30219-problam-using-_post/#findComment-138960 Share on other sites More sharing options...
Accurax Posted December 11, 2006 Author Share Posted December 11, 2006 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/ArrayWhich is not what i want ......... :( Quote Link to comment https://forums.phpfreaks.com/topic/30219-problam-using-_post/#findComment-138963 Share on other sites More sharing options...
HuggieBear Posted December 11, 2006 Share Posted December 11, 2006 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]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/30219-problam-using-_post/#findComment-138968 Share on other sites More sharing options...
Accurax Posted December 11, 2006 Author Share Posted December 11, 2006 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 ........ :) Quote Link to comment https://forums.phpfreaks.com/topic/30219-problam-using-_post/#findComment-138974 Share on other sites More sharing options...
HuggieBear Posted December 11, 2006 Share Posted December 11, 2006 No problem...The word 'array' in the path should have given it away.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/30219-problam-using-_post/#findComment-138976 Share on other sites More sharing options...
JasonLewis Posted December 12, 2006 Share Posted December 12, 2006 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... :) Quote Link to comment https://forums.phpfreaks.com/topic/30219-problam-using-_post/#findComment-139419 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.