Jump to content

[SOLVED] File upload not uploading


ldb358

Recommended Posts

this probably a simple issue but what the code is supposed to do is a) check if the user has a table if he doesn't it creates one then b) it creates a new directory for the file c) moves the temporary file there then finally inserts all the information about the file in the database but the problem is all of it works but the file doesn't exists afterwards

 

function upload($maxsize, $upload){

if((($upload['type'] == "image/jpeg") || ($upload['type'] == "image/pjpeg") || ($upload['type'] == "image/gif") || ($upload['type'] == "image/png")) && ($upload['size'] < "104857600")){

	if($upload['error'] == 0){

			$newSrc = $username . "/" . $upload['name'];		

			if(!file_exists($newSrc)){

			$nameFill = $upload['name'];

			$artistFill = $_SESSION['username'];

			$sizeFill = (int)$upload['size'];

			$check = mysql_query ("SELECT * FROM ".$artistFill." LIMIT 0,1"); 

			if($check){
			echo $upload['tmp_name'];
			$thisdir = getcwd(); 
			mkdir($thisdir ."/" . $artistFill);
			move_uploaded_file($upload['tmp_name'], $username . "/" . $upload['name']);
			mysql_query("INSERT INTO ".$artistFill." ( name, fType, fSize, artist) VALUES( '$nameFill', 'photo', '$sizeFill', '$artistFill');") or die(mysql_error());
			//move_uploaded_file($upload['tmp_name'],"/users" . $upload['name']);
			mysql_query("INSERT INTO ".$artistFill." ( name, fType, fSize, artist) VALUES( '$nameFill', 'photo', '$sizeFill', '$artistFill');") or die(mysql_error());
			echo "file uploaded";
			}else{

			//if table doesnt exsist
			$thisdir = getcwd(); 
			mkdir($thisdir ."/" . $artistFill, 777);
			move_uploaded_file($upload['tmp_name'],"/" . $artistFill. "/" . $upload['name']) or die("cant copy file");
			mysql_query("CREATE TABLE ".$artistFill."(id INT(10) NOT NULL AUTO_INCREMENT, name VARCHAR( 30 ) NOT NULL ,fType VARCHAR( 30 ) NOT NULL ,fSize INT NOT NULL ,artist VARCHAR( 30 ) NOT NULL ,fDesc TEXT NOT NULL ,rating INT(10) NOT NULL ,PRIMARY KEY (id))") or die(mysql_error()); 

			mysql_query("INSERT INTO ".$artistFill." (name, sType, fSize, artist) VALUES ('$nameFill', 'photo', 'sizeFill', '$artistFill');") or die(mysql_error());

			echo "added";

			}

			}

		}

	}

}

Link to comment
Share on other sites

For debugging purposes (remove them when you are done) add the following two lines of code immediately after your first opening <?php tag -

 

ini_set("display_errors", "1");
error_reporting(E_ALL);

 

Your code is blindly executing the queries and echoing success messages without even testing if the move_uploaded_file() statements worked or not.

Link to comment
Share on other sites

heres the error i got

 

Warning: move_uploaded_file(/Copy of Cross3Trans.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in /home/vol4/summerhost.info/sum_2677639/htdocs/test/functions.php on line 339

 

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpOwiLML' to '/Copy of Cross3Trans.jpg' in /home/vol4/summerhost.info/sum_2677639/htdocs/test/functions.php on line 339

Link to comment
Share on other sites

I'm going to guess you got a lot more relevant error messages, such as one about $username being undefined?

 

Where is the code setting $username to a value? Without a value, the code is attempting to move the uploaded file into the root of the hard disk, which you probably don't have permission to do, like the error you did post is stating.

Link to comment
Share on other sites

that is actually a variable from a different part of the script it is fixed now but still wont work

 

function upload($maxsize, $upload){

if((($upload['type'] == "image/jpeg") || ($upload['type'] == "image/pjpeg") || ($upload['type'] == "image/gif") || ($upload['type'] == "image/png")) && ($upload['size'] < "104857600")){

	if($upload['error'] == 0){

			$newSrc = $username . "/" . $upload['name'];		

			if(!file_exists($newSrc)){

			$nameFill = $upload['name'];

			$artistFill = $_SESSION['username'];

			$sizeFill = (int)$upload['size'];

			$check = mysql_query ("SELECT * FROM ".$artistFill." LIMIT 0,1"); 

			if($check){
			echo $upload['tmp_name'];
			$thisdir = getcwd(); 
			mkdir($thisdir ."/" . $artistFill);
			move_uploaded_file($upload['tmp_name'], $artistFill . "/" . $upload['name']);
			mysql_query("INSERT INTO ".$artistFill." ( name, fType, fSize, artist) VALUES( '$nameFill', 'photo', '$sizeFill', '$artistFill');") or die(mysql_error());
			//move_uploaded_file($upload['tmp_name'],"/users" . $upload['name']);
			mysql_query("INSERT INTO ".$artistFill." ( name, fType, fSize, artist) VALUES( '$nameFill', 'photo', '$sizeFill', '$artistFill');") or die(mysql_error());
			echo "file uploaded";
			}else{

			//if table doesnt exsist
			$thisdir = getcwd(); 
			mkdir($thisdir ."/" . $artistFill, 777);
			move_uploaded_file($upload['tmp_name'],"/" . $artistFill. "/" . $upload['name']) or die("cant copy file");
			mysql_query("CREATE TABLE ".$artistFill."(id INT(10) NOT NULL AUTO_INCREMENT, name VARCHAR( 30 ) NOT NULL ,fType VARCHAR( 30 ) NOT NULL ,fSize INT NOT NULL ,artist VARCHAR( 30 ) NOT NULL ,fDesc TEXT NOT NULL ,rating INT(10) NOT NULL ,PRIMARY KEY (id))") or die(mysql_error()); 

			mysql_query("INSERT INTO ".$artistFill." (name, sType, fSize, artist) VALUES ('$nameFill', 'photo', 'sizeFill', '$artistFill');") or die(mysql_error());

			echo "added";

			}

			}

		}

	}

}

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.