ldb358 Posted June 6, 2009 Share Posted June 6, 2009 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"; } } } } } Quote Link to comment https://forums.phpfreaks.com/topic/161218-solved-file-upload-not-uploading/ Share on other sites More sharing options...
ldb358 Posted June 6, 2009 Author Share Posted June 6, 2009 also to test the issue your self on my site http://lbflash.summerhost.info username:Lane password:enter1 Quote Link to comment https://forums.phpfreaks.com/topic/161218-solved-file-upload-not-uploading/#findComment-850698 Share on other sites More sharing options...
PFMaBiSmAd Posted June 6, 2009 Share Posted June 6, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/161218-solved-file-upload-not-uploading/#findComment-850704 Share on other sites More sharing options...
ldb358 Posted June 6, 2009 Author Share Posted June 6, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/161218-solved-file-upload-not-uploading/#findComment-850706 Share on other sites More sharing options...
PFMaBiSmAd Posted June 6, 2009 Share Posted June 6, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/161218-solved-file-upload-not-uploading/#findComment-850709 Share on other sites More sharing options...
ldb358 Posted June 6, 2009 Author Share Posted June 6, 2009 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"; } } } } } Quote Link to comment https://forums.phpfreaks.com/topic/161218-solved-file-upload-not-uploading/#findComment-850712 Share on other sites More sharing options...
ldb358 Posted June 6, 2009 Author Share Posted June 6, 2009 thank you very much it just started working... but it was the wrong variable being used so thanks for the help Quote Link to comment https://forums.phpfreaks.com/topic/161218-solved-file-upload-not-uploading/#findComment-850716 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.