scottrohe Posted August 8, 2006 Share Posted August 8, 2006 [b]EDIT: Well, last post at bottom ty for trying to help but that wasnt the problem ( that was just my bad when putting text into here, i was fooling around with it all before then.. turns out the problem was $_POST['file'] had to be $_FILES['file']..[/b]Ok so i'm trying to upload a file using a series of functions and cant get it to work. It seems like it's getting rid of the desired files directory so instead of uploading "c:\blah\blah.gif" its trying to upload blah.gif and is giving me hell.basicaly..[code=php:0] function procSubmitLayout(){ global $session, $form; $retval = $session->addLayout($_POST['title'], $_POST['cata'], $_POST['un'], $_POST['file'], $_POST['comm'], $_POST['Scode']);[/code]is my first function the form goes into, it then throws it over to sessions.php to check for errors.. note [file][code=php:0] function addLayout($subtitle, $subcata, $subun, $subfile, $subcomm, $subScode)[/code]is the start function in sessions.php ... note [subfile]then.. within that function.. check errors on file uploading, if none.. upload it.[code=php:0] $field = "file"; $field2 = "file2"; if($subfile == ""){ $form->setError($field, "* Screenshot not entered"); } else { $uploaddir = "/home/cetricc/public_html/eys/layouts/up"; $allowed_ext = "jpg, gif"; $max_size = "1048576"; // check file path $extension = pathinfo($_FILES['file']['name']); $extension = $extension[extension]; $allowed_paths = explode(", ", $allowed_ext); for($iz = 0; $i < count($allowed_paths); $i++) { if ($allowed_paths[$i] == "$extension") { $okk = "11"; } } if ($okk == "11") { if($_FILES['subfile']['size'] > $max_size) { $form->setError($field2, "* Image size is too large! *"); // show error on submit form.. } // upload if(is_uploaded_file($_FILES['file']['tmp_name'])) { move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.'/'.$_FILES['file']['tmp_name']); } } else { $form->setError($field2, "* You can only upload .jpg or .gif ScreenShots. *"); // show error on submit form.. }[/code]after that, it throws it over to database.php to add the gathered info to the database.. it correctly adds JUST "test.gif" or whatever the file may be to the database. which is what i wanted, but.. it doesnt upload the file.. ive tried it other ways and basicaly i can get it to output the error for invalid extension, and when i echo the result it just shows 'test.gif'. ive also tried changing 'file' variable within the uploading process to 'subfile'.. same result. hope i explained myself well enough. on another note..the code alone, just the file upload part with error checking works fine on a test form page.. so i know thats not the problem, its the input thats the problem.. grr.any help is much appreciated. Link to comment https://forums.phpfreaks.com/topic/16865-uploading-a-file-within-a-function-resolved/ Share on other sites More sharing options...
scottrohe Posted August 8, 2006 Author Share Posted August 8, 2006 bump Link to comment https://forums.phpfreaks.com/topic/16865-uploading-a-file-within-a-function-resolved/#findComment-71304 Share on other sites More sharing options...
scottrohe Posted August 8, 2006 Author Share Posted August 8, 2006 hmm, ive tried adding the upload code to the forms page, then having the process return as a diff url; ex: ?x=submit&added=yes... then if added = yes, try to upload the image.. but still cant get it to, it just echos the same thing 'test.gif' instead of the full dir.. any help would be much appreciated, thanks. Link to comment https://forums.phpfreaks.com/topic/16865-uploading-a-file-within-a-function-resolved/#findComment-71425 Share on other sites More sharing options...
scottrohe Posted August 9, 2006 Author Share Posted August 9, 2006 bump . . . Link to comment https://forums.phpfreaks.com/topic/16865-uploading-a-file-within-a-function-resolved/#findComment-71615 Share on other sites More sharing options...
redarrow Posted August 9, 2006 Share Posted August 9, 2006 what operrating system you using. Link to comment https://forums.phpfreaks.com/topic/16865-uploading-a-file-within-a-function-resolved/#findComment-71636 Share on other sites More sharing options...
scottrohe Posted August 9, 2006 Author Share Posted August 9, 2006 php - 4.4.2sql - 4.1.19-standard Link to comment https://forums.phpfreaks.com/topic/16865-uploading-a-file-within-a-function-resolved/#findComment-71694 Share on other sites More sharing options...
scottrohe Posted August 9, 2006 Author Share Posted August 9, 2006 rofl.. yay.. another bump :'( Link to comment https://forums.phpfreaks.com/topic/16865-uploading-a-file-within-a-function-resolved/#findComment-71951 Share on other sites More sharing options...
scottrohe Posted August 10, 2006 Author Share Posted August 10, 2006 AHHHHH Link to comment https://forums.phpfreaks.com/topic/16865-uploading-a-file-within-a-function-resolved/#findComment-72199 Share on other sites More sharing options...
hitman6003 Posted August 10, 2006 Share Posted August 10, 2006 Your first post doesn't make a lot of sense, but I did notice a few things...Why are you name it on the server's file system the temp name?[code]move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.'/'.$_FILES['file']['tmp_name'])[/code]Use $_FILES['file']['name'] to name it the actual name of the file.You aren't being consistent in which member of the $_FILES array you are referring to:[code]if($_FILES['subfile']['size'] > $max_size)[/code]Where did subfile come from? You use "file" in the others. Link to comment https://forums.phpfreaks.com/topic/16865-uploading-a-file-within-a-function-resolved/#findComment-72206 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.