Jump to content


Photo

Uploading a file within a function [Resolved]


  • Please log in to reply
8 replies to this topic

#1 scottrohe

scottrohe
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 08 August 2006 - 07:08 AM

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']..

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..
   function procSubmitLayout(){
      global $session, $form;
      $retval = $session->addLayout($_POST['title'], $_POST['cata'], $_POST['un'], $_POST['file'], $_POST['comm'], $_POST['Scode']);
is my first function the form goes into, it then throws it over to sessions.php to check for errors.. note [file]

 function addLayout($subtitle, $subcata, $subun, $subfile, $subcomm, $subScode)
is the start function in sessions.php ... note [subfile]

then.. within that function.. check errors on file uploading, if none.. upload it.
     $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..
	}
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.

#2 scottrohe

scottrohe
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 08 August 2006 - 06:57 PM

bump

#3 scottrohe

scottrohe
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 08 August 2006 - 09:34 PM

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.

#4 scottrohe

scottrohe
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 09 August 2006 - 04:52 AM

bump . . .

#5 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 09 August 2006 - 06:26 AM

what operrating system you using.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#6 scottrohe

scottrohe
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 09 August 2006 - 11:05 AM

php - 4.4.2
sql - 4.1.19-standard

#7 scottrohe

scottrohe
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 09 August 2006 - 06:34 PM

rofl.. yay.. another bump  :'(

#8 scottrohe

scottrohe
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 10 August 2006 - 01:33 AM

AHHHHH

#9 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 10 August 2006 - 01:44 AM

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?

move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.'/'.$_FILES['file']['tmp_name'])

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:

if($_FILES['subfile']['size'] > $max_size)

Where did subfile come from?  You use "file" in the others.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users