alsouno Posted September 21, 2007 Share Posted September 21, 2007 We had a comprehensive uploading feature based on PHP for our website, but since we recently changed servers it seems to be giving us problems. I've looked into the permission settings, etc and everything seems intact, but i am still not able to upload files. Not sure if posting code will necessarily make a difference, but I can if needed. Has anyone had similar issues, or aware of what might be the cause? Any insight would be greatly appreciated Quote Link to comment https://forums.phpfreaks.com/topic/70162-uploading-issues/ Share on other sites More sharing options...
HuggieBear Posted September 21, 2007 Share Posted September 21, 2007 How about an error message for a start. Code would also be a plus. Regards Huggie Quote Link to comment https://forums.phpfreaks.com/topic/70162-uploading-issues/#findComment-352355 Share on other sites More sharing options...
alsouno Posted September 21, 2007 Author Share Posted September 21, 2007 I created a test case which has the following code: [pre] <?php $host="****"; // Host name $username="****"; // Mysql username $password="****"; // Mysql password $db_name="****"; // Database name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); //upload file $target = "images/"; $target = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; $filename = "./".basename( $_FILES['uploaded']['name']) ; if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else { echo "Sorry, there was a problem uploading your file."; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Upload TEST</title> </head> <body> <br/> test... </body> [/pre] and it gives the "sorry there was a problem uploading your file" message... i tried displaying a table from my db on the page and it works fine but i can't seem to upload onto my ftp. Quote Link to comment https://forums.phpfreaks.com/topic/70162-uploading-issues/#findComment-352361 Share on other sites More sharing options...
HuggieBear Posted September 21, 2007 Share Posted September 21, 2007 So there's another page that submits to this one is there? One with a form I take it? Regards Huggie Quote Link to comment https://forums.phpfreaks.com/topic/70162-uploading-issues/#findComment-352382 Share on other sites More sharing options...
alsouno Posted September 21, 2007 Author Share Posted September 21, 2007 Yep. I just have a simple form setup that passes through the data to this page... The body of that page contains: <p> <form enctype="multipart/form-data" action="upload2.php" method="POST"> File: <input name="uploaded" type="file" /> <input type="submit" value="Upload" /> </form></p> Thanks Quote Link to comment https://forums.phpfreaks.com/topic/70162-uploading-issues/#findComment-352395 Share on other sites More sharing options...
HuggieBear Posted September 21, 2007 Share Posted September 21, 2007 Try something really simple at first, like this: <?php // Check the error code if ($_FILES['uploaded']['error'] == 0) { // Just use the file name and save in the current location $target = basename($_FILES['uploaded']['name']); if (move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "File moved OK"; } else { echo "Couldn't move file"; } } else { echo "There was an error uploading the file"; } Regards Huggie Quote Link to comment https://forums.phpfreaks.com/topic/70162-uploading-issues/#findComment-352411 Share on other sites More sharing options...
alsouno Posted September 21, 2007 Author Share Posted September 21, 2007 Using your code, I get the following: "Couldn't move file"... Quote Link to comment https://forums.phpfreaks.com/topic/70162-uploading-issues/#findComment-352415 Share on other sites More sharing options...
HuggieBear Posted September 21, 2007 Share Posted September 21, 2007 Try this then... <?php // Check the error code if ($_FILES['uploaded']['error'] == 0) { // Is the current directory writable if (is_writable(dirname(__FILE__))) { // Just use the file name and save in the current location $target = basename($_FILES['uploaded']['name']); echo "Trying to move " . $_FILES['uploaded']['tmp_name'] . " to " . $target; if (move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "File moved OK"; } else { echo "Couldn't move file"; } } else { echo "Directory isn't writable"; } else { echo "There was an error uploading the file"; } ?> Regards Huggie Quote Link to comment https://forums.phpfreaks.com/topic/70162-uploading-issues/#findComment-352420 Share on other sites More sharing options...
alsouno Posted September 21, 2007 Author Share Posted September 21, 2007 That code doesn't seem to work... Quote Link to comment https://forums.phpfreaks.com/topic/70162-uploading-issues/#findComment-352429 Share on other sites More sharing options...
MadTechie Posted September 21, 2007 Share Posted September 21, 2007 thats usful.. it doesn't work... and.. what error etc? Quote Link to comment https://forums.phpfreaks.com/topic/70162-uploading-issues/#findComment-352440 Share on other sites More sharing options...
HuggieBear Posted September 21, 2007 Share Posted September 21, 2007 Sorry, Missed off a closing bracket. Try this (tested and working)... <?php // Check the error code if ($_FILES['uploaded']['error'] == 0) { // Is the current directory writable if (is_writable(dirname(__FILE__))) { // Just use the file name and save in the current location $target = basename($_FILES['uploaded']['name']); echo "Trying to move " . $_FILES['uploaded']['tmp_name'] . " to " . $target; if (move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "File moved OK"; } else { echo "Couldn't move file"; } } else { echo "Directory isn't writable"; } } else { echo "There was an error uploading the file"; } ?> Regards Huggie Quote Link to comment https://forums.phpfreaks.com/topic/70162-uploading-issues/#findComment-352443 Share on other sites More sharing options...
alsouno Posted September 21, 2007 Author Share Posted September 21, 2007 Sorry for being lazy and not realizing the missing closing bracket myself :-\ Anyways, using your code, I still get "Couldn't move file"... Quote Link to comment https://forums.phpfreaks.com/topic/70162-uploading-issues/#findComment-352447 Share on other sites More sharing options...
HuggieBear Posted September 21, 2007 Share Posted September 21, 2007 And what was the echo output? Regards Huggie Quote Link to comment https://forums.phpfreaks.com/topic/70162-uploading-issues/#findComment-352449 Share on other sites More sharing options...
alsouno Posted September 21, 2007 Author Share Posted September 21, 2007 The echo output is as follows: Trying to move C:\WINDOWS\TEMP\php78.tmp to test.htmlCouldn't move file Quote Link to comment https://forums.phpfreaks.com/topic/70162-uploading-issues/#findComment-352456 Share on other sites More sharing options...
MadTechie Posted September 21, 2007 Share Posted September 21, 2007 change $target = basename($_FILES['uploaded']['name']); echo "Trying to move " . $_FILES['uploaded']['tmp_name'] . " to " . $target; if (move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) to $target = basename($_FILES['uploaded']['name']); $targetpath = "uploads/"; //<---set this to the upload PATH, make sure is writeable $target = $targetpath.$target; echo "Trying to move " . $_FILES['uploaded']['tmp_name'] . " to " . $target; if (move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) Quote Link to comment https://forums.phpfreaks.com/topic/70162-uploading-issues/#findComment-352628 Share on other sites More sharing options...
alsouno Posted September 21, 2007 Author Share Posted September 21, 2007 It's still displaying the same message :-\ Quote Link to comment https://forums.phpfreaks.com/topic/70162-uploading-issues/#findComment-352668 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.