corillo181 Posted November 28, 2006 Share Posted November 28, 2006 why isn't this code working?<?phpif(isset($_POST['Submit'])){$dir='image/';$filename = $_FILES['ulfile']['name'];$random = rand(0,9999999999);$pos = strrpos($filename, '.');$newname = $random . substr($filename, $pos);$tmpname = $_FILES['ulfile']['tmp_name'];$filesize = $_FILES['ulfile']['size'];$filetype = $_FILES['ulfile']['type'];$datetime = date('m-d-y h:i:s');$filepath = $dir . $newname;$result=copy($tmpname, $filepath);if(!$result){echo "not done";}}?> Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted November 28, 2006 Share Posted November 28, 2006 sure you set your enctype correctly in your form?<form [...snip...] enctype="multipart/form-data"> Quote Link to comment Share on other sites More sharing options...
corillo181 Posted November 28, 2006 Author Share Posted November 28, 2006 <form action="ul.php" method="post" enctype="multipart/form-data" name="ul" id="ul"> <input type="file" name="imagefile"> <input type="submit" name="Submit" value="Submit"> </form>sorry this is the firs tpart of the code Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted November 28, 2006 Share Posted November 28, 2006 [quote author=corillo181 link=topic=116550.msg474953#msg474953 date=1164695159]<form action="ul.php" method="post" enctype="multipart/form-data" name="ul" id="ul"> <input type="file" name="imagefile"> <input type="submit" name="Submit" value="Submit"> </form>sorry this is the firs tpart of the code[/quote]$_FILES['ulfile'] ... <input type="file" name="imagefile"> Match em up ^.^? Quote Link to comment Share on other sites More sharing options...
corillo181 Posted November 28, 2006 Author Share Posted November 28, 2006 [code]<form action="ul.php" method="post" enctype="multipart/form-data" name="ul" id="ul"> <input type="file" name="ulfile"> <input type="submit" name="Submit" value="Submit"> </form>[/code][code]<?phpif(isset($_POST['Submit'])){$dir='image/';$filename = $_FILES['ulfile']['name'];$random = rand(0,9999999999);$pos = strrpos($filename, '.');$newname = $random . substr($filename, $pos);$tmpname = $_FILES['ulfile']['tmp_name'];$filesize = $_FILES['ulfile']['size'];$filetype = $_FILES['ulfile']['type'];$datetime = date('m-d-y h:i:s');$filepath = $dir . $newname;$result=copy($tmpname, $filepath);if(!$result){echo "not done";}}?>[/code]i still get the not done.. Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted November 28, 2006 Share Posted November 28, 2006 you dont have to copy the tmp_name, cant u just copy the name? Quote Link to comment Share on other sites More sharing options...
corillo181 Posted November 28, 2006 Author Share Posted November 28, 2006 i tried it, with out the emp but i still get the same result.. no result at all.. Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted November 28, 2006 Share Posted November 28, 2006 it worked for me :X it was named a string of numbers for the filename though, only change I made for my server was change $dir to match my directories... I had it all in one pageul.php....<form action="ul.php" method="post" enctype="multipart/form-data" name="ul" id="ul"> <input type="file" name="ulfile"> <input type="submit" name="Submit" value="Submit"> </form>[code=php:0]<?phpif(isset($_POST['Submit'])){$dir='image/';$filename = $_FILES['ulfile']['name'];$random = rand(0,9999999999);$pos = strrpos($filename, '.');$newname = $random . substr($filename, $pos);$tmpname = $_FILES['ulfile']['tmp_name'];$filesize = $_FILES['ulfile']['size'];$filetype = $_FILES['ulfile']['type'];$datetime = date('m-d-y h:i:s');$filepath = $dir . $newname;$result=copy($tmpname, $filepath);if(!$result){echo "not done";}}?>[/code] Quote Link to comment Share on other sites More sharing options...
corillo181 Posted November 28, 2006 Author Share Posted November 28, 2006 the action to make it wokr on the same page is [code]<?php $_SERVER['PHP_SELF'];?>[/code]right?i dont know why is not working for me :| Quote Link to comment Share on other sites More sharing options...
corillo181 Posted November 28, 2006 Author Share Posted November 28, 2006 oh it did work if i put it in the same page.. but if is in different page it doesn't work.. Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted November 28, 2006 Share Posted November 28, 2006 It works fine for me even if they are seperate....IF your form is in like...htdocs/uploadform.phpand your upload script is in like...htdocs/scripts/ul.phpthen you would need to do absolute directory listing to where you want to upload to (in your $dir string)eg.../home/local/apache2/htdocs/image/ This obviously is so because it's trying to upload to...htdocs/scripts/image/and that probably doesn't exist....Another alternative is you didn't chmod 777 your upload directory?Trying to go through all the alternatives. Quote Link to comment Share on other sites More sharing options...
corillo181 Posted November 28, 2006 Author Share Posted November 28, 2006 YEAH I FIXED SOME HOW.. I JUST TRIED TO UPLOAD A PIC AND IT WORKED BOTH WAYS NOW... I DONT KNOW WHAT WAS THE PROBLEM BEFORE BECUASE THE CODE STILL THE SAME.. BUT THANX FOR THE HELP GUYS.. Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted November 28, 2006 Share Posted November 28, 2006 All caps cuz you're excited, or because it's your 200th post o.o? Quote Link to comment Share on other sites More sharing options...
corillo181 Posted November 28, 2006 Author Share Posted November 28, 2006 lol well i didn't really notice it, but i think something inside of me is exicited about both.i already make galleries and websites, but i wasn't working programing for a while and felt like coming back so i'm trying to ge tthe hang of it.. i guess i'll say both. :) Quote Link to comment 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.