Search code examples
phppermissionsmamp

Can't upload image files to permanent folder in MAMP. Newbie


I am trying out some php/mysql resources and am stuck on uploading images to permanent folder with MAMP. This is the form:

<form action="create_user.php" method="post" enctype="multipart/form-data">
<fieldset>
<label for="first_name">First Name:</label>
<input type="text" name="first_name" size="20" /><br />
<label for="last_name">Last Name:</label>
<input type="text" name="last_name" size="20" /><br />
<label for="email">E-mail address:</label>
<input type="text" name="email" size="50" /><br />
<label for="facebook_url">Facebook URL:</label>
<input type="text" name="facebook_url" size="50" /><br />
<label for="twitter_handle">Twitter Handle:</label>
<input type="text" name="twitter_handle" size="20" /><br />
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<label for="user_pic">Upload a picture:</label>
<input type="file" name="user_pic" size="30" /><br />    
<label for="bio">Bio:</label>
<textarea name="bio" cols="40" rows="10"/></textarea>
</fieldset>
<br />

This is the code in my script interacting with the form:

$upload_dir = SITE_ROOT . "missmanphpmysql/uploads/profile_pics/";
$image_fieldname = "user_pic";

This is the function and custom function to check for permissions and the like:

@move_uploaded_file($_FILES[$image_fieldname]['tmp_name'], $upload_filename)
 or handle_error("we had a problem saving your image to " .
              "its permanent location.",
              "permissions or related error moving " .
              "file to {$upload_filename}");

All I get is the above error message. I have tried to change the permissions in finder and chmod but I may be doing it wrong. Any help greatly appreciated.


Solution

  • Did you set the folder permission correctly? profile_pics needs write permission. Try to use terminal and set 'chmod 777 profile_pics'.