Jump to content

file upload as a function


Box

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/192396-file-upload-as-a-function/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.