travelkind Posted November 22, 2009 Share Posted November 22, 2009 I have written this simple script to upload a file and am getting an error saying "Couldn't copy the file." I have checked the syntax and haven't found an error. Here is a snippet of the code: <? if ($_FILES[img1] != "") { @copy($_FILES[img1][tmp_name], "/html/beer/uploads/".$_FILES[img1][name1]) or die("Couldn't copy the file.") I have set the permissions on the folder permissions on the server to be read, write and execute. Here is my php.ini file: rg_emulation=off file_uploads = On upload_tmp_dir = /html/beer/uploads memory_limit = 50M post_max_size = 10M upload_max_filesize = 10M Should I rename the the file to php5.ini? Thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/182512-couldnt-copy-the-file-error/ Share on other sites More sharing options...
Alex Posted November 22, 2009 Share Posted November 22, 2009 You should take off the error suppressing from copy (@) so you can actually see what's going wrong, another good idea would be to put error_reporting(E_ALL); at the top of the file. Once you do that you'll get a bunch of undefined constant errors, you should surround indexes with quotes if they're strings. Ex: $_FILES[img1] should be $_FILES['img1']. Once you do that post back the error that copy is throwing. Quote Link to comment https://forums.phpfreaks.com/topic/182512-couldnt-copy-the-file-error/#findComment-963295 Share on other sites More sharing options...
travelkind Posted November 22, 2009 Author Share Posted November 22, 2009 Okay here is my code now: <? error_reporting(E_ALL) if ($_FILES[img1] != "") { @copy($_FILES['img1']['tmp_name'], "/html/beer/uploads/".$_FILES['img1']['name1']) or die("Couldn't copy the file."); and here is the error I am getting: Parse error: syntax error, unexpected T_IF in /home/content/d/l/a/dlanden/html/beer/do_upload.php on line 3 Quote Link to comment https://forums.phpfreaks.com/topic/182512-couldnt-copy-the-file-error/#findComment-963322 Share on other sites More sharing options...
Alex Posted November 22, 2009 Share Posted November 22, 2009 You didn't fix one of the indexes, or take off the error suppression from copy. Is that your whole code? If so you're never closing your if statement, which is why you're getting that error. if ($_FILES['img1'] != "") { copy($_FILES['img1']['tmp_name'], "/html/beer/uploads/".$_FILES['img1']['name1']) or die("Couldn't copy the file."); } Quote Link to comment https://forums.phpfreaks.com/topic/182512-couldnt-copy-the-file-error/#findComment-963326 Share on other sites More sharing options...
travelkind Posted November 22, 2009 Author Share Posted November 22, 2009 I made your changes and got this error: Parse error: syntax error, unexpected T_IF in /home/content/d/l/a/dlanden/html/beer/do_upload.php on line 4 Here is my complete code (for the php): <? error_reporting(E_ALL) if ($_FILES['img1'] != "") { copy($_FILES['img1']['tmp_name'], "/html/beer/uploads/".$_FILES['img1']['name1']) or die("Couldn't copy the file."); } else { die("No input file specified"); } ?> <HTML> <HEAD> <TILE>Successful File Upload</TITLE> </HEAD> <BODY> <H1>Success!</H1> <P>You sent: <? echo $_FILES[img1][name]; ?>, a <? echo $_FILES['img1']['size']; ?> byte file with a mime type of <? echo $_FILES['img1']['type']; ?>.</P> </BODY> </HTML> Thanks again for your help! Quote Link to comment https://forums.phpfreaks.com/topic/182512-couldnt-copy-the-file-error/#findComment-963329 Share on other sites More sharing options...
Alex Posted November 22, 2009 Share Posted November 22, 2009 You're missing a ; at the end of this line: error_reporting(E_ALL) Quote Link to comment https://forums.phpfreaks.com/topic/182512-couldnt-copy-the-file-error/#findComment-963334 Share on other sites More sharing options...
travelkind Posted November 22, 2009 Author Share Posted November 22, 2009 okay I added the ; and now I am getting this message / error: Notice: Undefined index: name1 in /home/content/d/l/a/dlanden/html/beer/do_upload.php on line 6 Warning: copy(/html/beer/uploads/) [function.copy]: failed to open stream: No such file or directory in /home/content/d/l/a/dlanden/html/beer/do_upload.php on line 6 Couldn't copy the file. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/182512-couldnt-copy-the-file-error/#findComment-963342 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.