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
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.