daveygz Posted May 10, 2023 Share Posted May 10, 2023 (edited) Hi All, This is my first post and I am not super good at coding with php so if this seems a bit "simple or "stupid" my apologies. I have this code (which works and will upload a photo and add info to the database) that I had finally gotten to work well. I edited it to upload a photo, a title and paypal button code. I have tried everything I can think of to make this code work and it's just not. It gives errors like this. Warning: move_uploaded_file(uploads/Decal.jpg): failed to open stream: No such file or directory in /home/website/public_html/paypal/paypal-add.php on line 15 Warning: move_uploaded_file(): Unable to move '/tmp/phpjVp2F8' to 'uploads/Decal.jpg' in /home/website/public_html/paypal/paypal-add.php on line 15 I am not sure why this exact code works to upload a file in another section of the site, but the code below always bombs. I did get it to work once, when I placed a php script at the top to display all the php settings of the web server. (No clue why) I am hoping someone out there will see that I have done wrong here and why this won't function. There is an uploads folder in the same folder as this code. The setting on the database are accurate to the variable in the code. The settings are also accurate. Any thoughts would be appreciated. The code. <?php include 'settings.php'; // Initialize DBase $con = mysqli_connect("$dbHost","$dbUsername","$dbPassword")or die('Could not connect: ' . mysqli_connect_error()); mysqli_select_db($con,"$dbName")or die("Cannot select the database."); // Set Variables $fileName = $_FILES['fileName']['name']; $statusMsg = ''; $product_name = $_POST['product_name']; $paypal_code = $_POST['paypal_code']; $PathName = "uploads/"; // Copy Image File To Directory And Write the information to the database $Success = move_uploaded_file($_FILES['fileName'] ['tmp_name'],$PathName.$fileName); if($Success) { $sql="INSERT INTO $table (fileName, product_name, paypal_code) VALUES ('$fileName','$product_name','$paypal_code')"; if(!mysqli_query($con,$sql)) {$statusMsg = 'There was an error saving the sample.';} else {header("Location: paypal-list.php");} } else {$statusMsg = 'There was an error saving the sample.';} mysqli_close($con); echo $statusMsg; exit; ?> Thanks Edited May 10, 2023 by daveygz Quote Link to comment https://forums.phpfreaks.com/topic/316284-no-clue/ Share on other sites More sharing options...
ginerjm Posted May 10, 2023 Share Posted May 10, 2023 (edited) Have you echoed out the contents of the move command to see what you are trying to do? And as I haven't done one of these in a bit, aren't you supposed to be moving a 'tmpname'? Oops - upon re-reading the broken display of the move line I see tmpname is being referenced. So I would want to see the contents of that move line to be sure the names you expect to be there are truly there. Edited May 10, 2023 by ginerjm Correction Quote Link to comment https://forums.phpfreaks.com/topic/316284-no-clue/#findComment-1608279 Share on other sites More sharing options...
requinix Posted May 10, 2023 Share Posted May 10, 2023 Does the uploads/ directory exist? And does it exist at (I think:) /paypal/uploads? 2 Quote Link to comment https://forums.phpfreaks.com/topic/316284-no-clue/#findComment-1608282 Share on other sites More sharing options...
Solution daveygz Posted May 25, 2023 Author Solution Share Posted May 25, 2023 (edited) Hi Guys, Thanks for the suggestions! Totally appreciated. The solution was the oddest thing. I am not sure if the page itself needed to be designated as a php or something, but when I added this bit of code to the very top of the code to check errors, it submitted perfectly; added the image and wrote all the info to the database. <?php error_reporting(E_ALL); ini_set('display_errors', 1); ?> As I just wanted to see what errors I was getting this was a total surprise. I appreciate all the help however! Thanks Guys!! Edited May 25, 2023 by daveygz Quote Link to comment https://forums.phpfreaks.com/topic/316284-no-clue/#findComment-1608670 Share on other sites More sharing options...
ginerjm Posted May 25, 2023 Share Posted May 25, 2023 you did something else as well. Enabling error checking didn't solve your problems. It would only tell you what coding mistakes you had. And stop using the ?> line. You don't need to do that all the time. Quote Link to comment https://forums.phpfreaks.com/topic/316284-no-clue/#findComment-1608671 Share on other sites More sharing options...
gizmola Posted May 26, 2023 Share Posted May 26, 2023 On 5/25/2023 at 8:41 AM, ginerjm said: you did something else as well. Enabling error checking didn't solve your problems. It would only tell you what coding mistakes you had. And stop using the ?> line. You don't need to do that all the time. @ginerjm makes a good point here. Omit the ending tag in all your scripts, unless you are going in and out of php mode. Even if you are doing that, you still never need a php end tag "?>" at the bottom of your script. Having one can lead to hard to debug errors, particularly when you are include/require scripts which you did in your code with your "settings.php" script. Quote Link to comment https://forums.phpfreaks.com/topic/316284-no-clue/#findComment-1608683 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.