Lyleyboy Posted January 27, 2010 Share Posted January 27, 2010 Hi all, I have a question. I have written a couple of scripts to upload files. They are only the basic version and I know they need a lot before they go into production but I'm just trying to get them to work. My issue is that these scripts work on all three servers I have access to but not on the guy's who I am writing them for. I have tested them on fasthosts, 1and1 and bargainhosts servers and this all works perfectly. The issue is that on mediatemple the script won't do the actual copy part. We don't get a specific error. I'm fairly certain that the issue lie in the php config but I am no expert with this at all. Does anyone have any idea's? My code for examples Version 1 <?php ############################ # Lets do some config # Specify the max size in KB i.e. 1000 bytes # So 1000 = 1MB and 1000000 = 1GB $maxSize = "1000"; # Now we need to tell the program where to put the file it uploads $location = "/path to file/"; ########################### #ÊDO NOT MESS BELOW THIS LINE # if(isset($_POST['Submit'])){ define ("MAX_SIZE",$maxSize); $errors=0; $image=$_FILES['image']['name']; if($image){ $filename = stripslashes($_FILES['image']['name']); $size=filesize($_FILES['image']['tmp_name']); if ($size > MAX_SIZE*1024) { echo 'That file is too big!'; $errors=1; } $newname=$location.$filename; $copied = copy($_FILES['image']['tmp_name'], $newname); if (!$copied){ echo 'It didnt work!'; $errors=1; } } } else { showForm(); } if(isset($_POST['Submit']) && !$errors){ echo "File Uploaded Successfully!"; } function showForm(){ ?> <form method="post" enctype="multipart/form-data" action=""> <input type="file" name="image"> <input name="Submit" type="submit" value="Upload"> </form> <? } ?> Version 2 <?php ############################ # Lets do some config # Specify the max size in bytes i.e. 1000 bytes # So 1000 = 1KB and 1000000 = 1MB and 1000000000 = 1GB $maxSize = "1000000"; # Now we need to tell the program where to put the file it uploads $location = "/path to files/"; ########################### #ÊDO NOT MESS BELOW THIS LINE # if(isset($_POST['sub'])){ $target_path = $location . basename( $_FILES['filename']['name']); if(basename( $_FILES['filename']['size']) > $maxSize){ $errors =1; echo "The file is too big at " . basename( $_FILES['filename']['size']) . " bytes. We are restricted to " . $maxSize . " bytes"; } if(isset($_POST['sub']) && !$errors){ if(move_uploaded_file($_FILES['filename']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['filename']['name']). " has been uploaded. "; echo "The file was " . basename( $_FILES['filename']['size']). " bytes. <br/>"; echo "Fancy another go?<br/>"; showForm(); } else { echo "There was an error uploading the file, please try again!<br/>"; showForm(); } } else { echo " Sorry, it's a no go"; showForm(); } } else { showForm(); } function showForm(){ ?> <form enctype="multipart/form-data" action="" method="post"> <input type="hidden" name="sub" value="1" /> Choose a file to upload <input type="file" name="filename"/> <input type="submit" value="Upload" /> </form> <? } ?> Quote Link to comment https://forums.phpfreaks.com/topic/189986-problem-uploading-files/ Share on other sites More sharing options...
jl5501 Posted January 27, 2010 Share Posted January 27, 2010 The most likely issue, is the permissions on the target directory. This will need to be set to 777, which you can probably do with your ftp program Quote Link to comment https://forums.phpfreaks.com/topic/189986-problem-uploading-files/#findComment-1002349 Share on other sites More sharing options...
Lyleyboy Posted January 27, 2010 Author Share Posted January 27, 2010 I should have mentioned that. I've done that. Set all perms to 777. Same issues. It's really random and making my head hurt. Quote Link to comment https://forums.phpfreaks.com/topic/189986-problem-uploading-files/#findComment-1002350 Share on other sites More sharing options...
jl5501 Posted January 27, 2010 Share Posted January 27, 2010 Another silly question I am assuming you have changed the - path to files - to be the actual directory path you wish to upload to Quote Link to comment https://forums.phpfreaks.com/topic/189986-problem-uploading-files/#findComment-1002373 Share on other sites More sharing options...
Lyleyboy Posted January 27, 2010 Author Share Posted January 27, 2010 I have. To cheat and make sure I let the script error and copied the path from there so I know it's accurate. Quote Link to comment https://forums.phpfreaks.com/topic/189986-problem-uploading-files/#findComment-1002400 Share on other sites More sharing options...
PFMaBiSmAd Posted January 27, 2010 Share Posted January 27, 2010 Add the following lines of debugging code immediately after the first opening <?php tag and tell us what is displays after the form is submitted - ini_set("display_startup_errors", "1"); ini_set("display_errors", "1"); error_reporting(E_ALL); echo "<pre>"; echo "POST:"; print_r($_POST); echo "FILES:"; print_r($_FILES); echo "</pre>"; Quote Link to comment https://forums.phpfreaks.com/topic/189986-problem-uploading-files/#findComment-1002407 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.