Cannot upload with PHP

liunx

Guest
My file upload script is not working. Can anyone help?<br /><br />This is only part of my script, but I think it's the only part with problems:<br /><br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->$uploadDir = '/uploadedfiles/';<br />$uploadFile = $uploadDir . $_FILES['file']['name'];<br />if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadFile))<br />{<br />    print "File is valid, and was successfully uploaded. ";<br /><br />}<br />else<br />{<br />    print "There was an error uploading the file.  Please try again.";<br />     print_r($_FILES);<br />exit;<br />}<!--c2--></div><!--ec2--><br /><br />This is the error I get, as well as my programmed error<br /><br />Warning: move_uploaded_file(/uploadedfiles/1210_14_2_web.jpg): failed to open stream: No such file or directory in /home/tcecom/public_html/upload2.php on line 56<br /><br />Isn't this a problem with the server. Do I need to change permissions? Thanks <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/cool.gif" style="vertical-align:middle" emoid="B)" border="0" alt="cool.gif" /><!--content-->
Ok, I aint sure if this is what your asking for, but it is helpful to me, and you might find what the problem is by looking through this Tutorial @ Dev's Articles: <br /><br /><a href="http://www.devarticles.com/c/a/PHP/Creating_a_MultiFile_Upload_Script_in_PHP/3/" target="_blank">http://www.devarticles.com/c/a/PHP/Creatin...cript_in_PHP/3/</a><!--content-->
<!--quoteo--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--quotec-->Isn't this a problem with the server. Do I need to change permissions? Thanks<!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />If you think it is then you might try dropping a ticket and letting the TCH Staff take a look and see if they can find out what is going on.<br /><br /><a href="https://ssl.totalchoicehosting.com/supportdesk/" target="_blank">https://ssl.totalchoicehosting.com/supportdesk/ </a><!--content-->
It looks like $uploadDir is set incorrectly. Try this:<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->$uploadDir = '/home/your_username_here/public_html/uploadedfiles/';<br />// Other code unchanged<!--c2--></div><!--ec2--><br /><br />Where your_username_here is your TCH username.<br /><br />With PHP filesystem functions, pathnames are relative to the server root and not your own public_html directory. Your original code is trying to write to a directory just under the server root directory, which presumably doesn't exist (and of course, you wouldn't have permission to access it even if it did exist).<br /><br />Edited to add:<br />Alternately, you could use a relative path such as<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->$uploadDir = 'uploadedfiles/';<!--c2--></div><!--ec2--><br /><br />Note that there is no slash at the beginning of the path. Maybe this is what you meant to do? Since the script is located in your public_html directory, 'uploadedfiles/' points to '/home/your_username_here/public_html/uploadedfiles/'<br /><br />That will work too, but I prefer to use complete path names whenever possible. That way a script doesn't break if you decide to move it to a different directory.<!--content-->
Thanks jesse, that did it! woooot <br /><br />Thank you all you guys for your suggestions. And thanks for the quick responses.<br /><br />Have a great day.<!--content-->
 
Back
Top