Box Posted February 17, 2010 Share Posted February 17, 2010 I'm making a admin system in which a few pages will have the ability to upload files to various sections so to make things neat and small i'd like to make an upload function to call rather than having the same/similar code in multiple pages Below is the code i've wrote which worked before it was a function but not after. I think my issue is passing the data to the function function takefile($filename, $newname, $target_path, $thumb) { $ext =explode('.', $_FILES[$filename]['name']); $ext = ".".$ext[count($ext)-1]; $target_path = $target_path.$newname.$ext; if(move_uploaded_file($_FILES[$filename]['tmp_name'], $target_path)) { echo "The picture ". basename( $_FILES[$filename]['name']). " has been uploaded<br />"; //make profile pic if ($thumb == "Y") { //not important right now } } else { echo "There was an error uploading the picture, please try again!<br />"; } } the form and calling parts of the code are: <input name="aim" type="file"> <br /><a href="managecategories.php?dp=<? echo($row['catid']); ?>">[delete current picture]</a> </td> takefile('aim','test','..images/buttons/','N'); can someone please tell me how I can do this? Or see whats going wrong? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/192396-file-upload-as-a-function/ Share on other sites More sharing options...
premiso Posted February 17, 2010 Share Posted February 17, 2010 takefile('aim','test','..images/buttons/','N'); From what you posted is not inside of <?php ?> or <? ?> so it will just display as text, unless you did not post the exact code. Quote Link to comment https://forums.phpfreaks.com/topic/192396-file-upload-as-a-function/#findComment-1013770 Share on other sites More sharing options...
Box Posted February 17, 2010 Author Share Posted February 17, 2010 that line is between some earlier <? brackets i only posted the line that called it, the last 2 bits of code dont directly follow each other. it was jsut to show the variable names of the form and the line that calls the main function Quote Link to comment https://forums.phpfreaks.com/topic/192396-file-upload-as-a-function/#findComment-1014018 Share on other sites More sharing options...
LeadingWebDev Posted February 17, 2010 Share Posted February 17, 2010 takefile('aim','test','../images/buttons/','N'); may be the path is a problem? slash at beginning. Quote Link to comment https://forums.phpfreaks.com/topic/192396-file-upload-as-a-function/#findComment-1014023 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.