firoki Posted February 16, 2007 Share Posted February 16, 2007 Hi everybody, I found this upload code and tried it out on my site. The file uploads but I get this weird error Step1 (upload.html) - find a file and click upload Step2 (upload.php) - webpage says "Notice: Undefined index: uploadedfile in /www/1111mb.com/m/a/d/madtracks/htdocs/upload.php on line 7 The file has been uploaded" And yes, it uploads, but I don't how how to fix the unidentified index thing (i've attached the files so you can have a peek) any ideas? thanks [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 16, 2007 Share Posted February 16, 2007 Before you use a variable you'll want to check if it's set and if not, declare it. if(!isset($uploadedfile)){ $uploadedfile = ''; } Quote Link to comment Share on other sites More sharing options...
firoki Posted February 16, 2007 Author Share Posted February 16, 2007 could you show me where to put it? <?php $target = "upload/"; $target = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else { echo "Sorry, there was a problem uploading your file."; } ?> Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 16, 2007 Share Posted February 16, 2007 before you try to use the variable, so before the code you posted you'd add if(isset($_FILES['uploaded']['name'])){ Quote Link to comment Share on other sites More sharing options...
firoki Posted February 16, 2007 Author Share Posted February 16, 2007 so this? <?php if(isset($_FILES['uploaded']['name'])){ $target = "upload/"; $target = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else { echo "Sorry, there was a problem uploading your file."; } ?> if i use that i get: Parse error: parse error, unexpected $ in /www/1111mb.com/m/a/d/madtracks/htdocs/upload.php on line 13 Quote Link to comment Share on other sites More sharing options...
monk.e.boy Posted February 16, 2007 Share Posted February 16, 2007 <?php if(isset($_FILES['uploaded']['name'])) { $target = "upload/"; $target = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else { echo "Sorry, there was a problem uploading your file."; } } ?> are you missing a } at the end? Quote Link to comment Share on other sites More sharing options...
firoki Posted February 16, 2007 Author Share Posted February 16, 2007 i tried your version monk.e.boy but i get: Notice: Undefined index: uploadedfile in /www/1111mb.com/m/a/d/madtracks/htdocs/upload.php on line 9 The file has been uploaded Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 16, 2007 Share Posted February 16, 2007 You use $_FILES['uploaded'] one spot, and then uploadedfile another. use the same name Quote Link to comment Share on other sites More sharing options...
firoki Posted February 16, 2007 Author Share Posted February 16, 2007 im sorry but i dont know what you mean, i dont actually know much (hardly anything really) about php would anyone mind putting the code together for me so it works? Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 16, 2007 Share Posted February 16, 2007 if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } The two variables are not the same. One says uploaded and one says uploadedfile. It needs to be the name of your input in your form, which I assume is uploaded. Quote Link to comment Share on other sites More sharing options...
firoki Posted February 16, 2007 Author Share Posted February 16, 2007 woohoo! you did it i understand what you mean now, about the uploaded/uploadedfile thing, i changed uploadedfile to uploaded and it works bloody perfect! thanks jesirose and monk.e.boy! 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.