webguync Posted November 19, 2010 Author Share Posted November 19, 2010 the echo isn't occurring apparently. Quote Link to comment Share on other sites More sharing options...
ManiacDan Posted November 19, 2010 Share Posted November 19, 2010 And yet you claim the function is succeeding. So you're uploading a fresh picture, one you've never used before, and you're seeing it in the directory? But you don't see an echo or any more errors? That's not really possible. -Dan Quote Link to comment Share on other sites More sharing options...
joel24 Posted November 19, 2010 Share Posted November 19, 2010 you've set error reporting to e_all? error_reporting(E_ALL); and try using copy() rather than move_uploaded_file() to see if that works to ensure its not a folder/file permissions problem. and then use file_exists(); to ensure the file exists i.e. if if (file_exists($_FILES['myfile']['tmp_name']) && copy($_FILES['myfile']['tmp_name'], $uploadFile)) { $statement = "insert into Profile_Photos (filename) values ('{$uploadFile}')"; echo "<P>".$statement; mysql_query($statement); echo "<P>".mysql_error(); [code=php:0] //change copy back to move_uploaded_file(); when you've completed debugging Quote Link to comment Share on other sites More sharing options...
webguync Posted November 20, 2010 Author Share Posted November 20, 2010 I think I figured out the problem. Since I took the JS away to get this working, I was still usng the IF statement looking for the JS. Moved the INSERT up to the 1) JS is turned off and it worked. <?php ini_set("display_errors","1"); ERROR_REPORTING(E_ALL); $db_user = ""; $db_pass = ""; $db = ""; $link = mysql_connect('localhost',$db_user,$db_pass); $db_selected = mysql_select_db($db); /*debugging*/ if (!$link) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; if (!$db_selected) { die ('Can\'t use foo : ' . mysql_error()); } $uploadDir = dirname(__FILE__) . '/files/'; $uploadFile = $uploadDir . basename($_FILES['myfile']['name']); //Print_r ($_FILES); if ($_POST['submit'] != '') { // 1. submitting the html form if (!isset($_GET['jqUploader'])) { // 1.a javascript off, we need to upload the file if (move_uploaded_file ($_FILES['myfile']['tmp_name'], $uploadFile)) { $statement = "insert into Profile_Photos (Path_to_File) values ('{$uploadFile}')"; echo "<P>".$statement; mysql_query($statement); echo "<P>".mysql_error(); // delete the file // @unlink ($uploadFile); $html_body = '<h1>File successfully uploaded!</h1><pre>'; $html_body .= print_r($_FILES, true); $html_body .= '</pre>'; } else { $html_body = '<h1>File upload error!</h1>'; switch ($_FILES['myfile']['error']) { case 1: $html_body .= 'The file is bigger than this PHP installation allows'; break; case 2: $html_body .= 'The file is bigger than this form allows'; break; case 3: $html_body .= 'Only part of the file was uploaded'; break; case 4: $html_body .= 'No file was uploaded'; break; default: $html_body .= 'unknown errror'; } $html_body .= 'File data received: <pre>'; $html_body .= print_r($_FILES, true); $html_body .= '</pre>'; } $html_body = '<h1>Results</h1><pre>'; $html_body .= print_r($_POST, true); $html_body .= '</pre>'; } else { // 1.b javascript on, so the file has been uploaded and its filename is in the POST array $html_body = '<h1>Form posted!</h1><p>Error:<pre>'; $html_body .= print_r($_POST, false); $html_body .= '</pre>'; } myHtml($html_body); } else { if ($_GET['jqUploader'] == 1) { // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // 2. performing jqUploader flash upload if ($_FILES['myfile']['name']) { if (move_uploaded_file ($_FILES['myfile']['tmp_name'], $uploadFile)) { // $statement = "insert into Profile_Photos (filename) values ('{$uploadFile}')"; // echo "<P>".$statement; // mysql_query($statement); // echo "<P>".mysql_error(); //delete the file //@unlink ($uploadFile); return $uploadFile; } } else { if ($_FILES['myfile']['error']) { return $_FILES['myfile']['error']; } } } } // /////////////////// HELPER FUNCTIONS function myHtml($bodyHtml) { ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>File Upload</title> <link rel="stylesheet" type="text/css" media="screen" href="style.css"/> </head> <body> <?php echo $bodyHtml; ?> </body> </html> <?php } ?> Quote Link to comment 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.