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] Link to comment https://forums.phpfreaks.com/topic/38778-solved-php-upload-form-unidentified-index/ 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 = ''; } Link to comment https://forums.phpfreaks.com/topic/38778-solved-php-upload-form-unidentified-index/#findComment-186341 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."; } ?> Link to comment https://forums.phpfreaks.com/topic/38778-solved-php-upload-form-unidentified-index/#findComment-186346 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'])){ Link to comment https://forums.phpfreaks.com/topic/38778-solved-php-upload-form-unidentified-index/#findComment-186358 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 Link to comment https://forums.phpfreaks.com/topic/38778-solved-php-upload-form-unidentified-index/#findComment-186384 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? Link to comment https://forums.phpfreaks.com/topic/38778-solved-php-upload-form-unidentified-index/#findComment-186386 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 Link to comment https://forums.phpfreaks.com/topic/38778-solved-php-upload-form-unidentified-index/#findComment-186402 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 Link to comment https://forums.phpfreaks.com/topic/38778-solved-php-upload-form-unidentified-index/#findComment-186404 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? Link to comment https://forums.phpfreaks.com/topic/38778-solved-php-upload-form-unidentified-index/#findComment-186413 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. Link to comment https://forums.phpfreaks.com/topic/38778-solved-php-upload-form-unidentified-index/#findComment-186416 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! Link to comment https://forums.phpfreaks.com/topic/38778-solved-php-upload-form-unidentified-index/#findComment-186422 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.