Haven't found anything that quite fits what is happening to me, but maybe you do. You should know that I'm in local environment, using apache & php in MAMP.
I am uploading a file image to a folder (uploads), which lies in the root folder (htdocs). Problem is that when, let's say, capybara.jpg gets uploaded, it ends up as uploadscapybara.jpg outside of the uploads folder.
My php is below
$name = $_FILES['image']['name'];
//$size = $_FILES['image']['size'];
//$type = $_FILES['image']['type'];
$tmp_name = $_FILES['image']['tmp_name'];
if (isset($name)) {
if (!empty($name)) {
$location = 'uploads';
if (move_uploaded_file($tmp_name, $location.$name)) {
echo 'uploaded!';
}
} else {
echo 'Please choose a file';
}
}
I get no warning of any kind as the php is above, but still have the problem. if I try adding a slash to uploads, writing $location = '/uploads'
I will get
Warning: move_uploaded_file(/uploadsCapybara.jpg): failed to open stream: Permission denied in /Applications/MAMP/htdocs/uploadfile.php on line 22
Warning: move_uploaded_file(): Unable to move '/Applications/MAMP/tmp/php/phpCTLZgH' to '/uploadsCapybara.jpg' in
I went into the folder, clicked Get Info, and changed Privelege to Read and Write for superuser and admin. I wrote an alias mod which is what gets the file to upload at all and then wrote a directory for that <Directory "/Applications/MAMP/uploads">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
,
And I also wrote include_path for the folder.
".:/Applications/MAMP/bin/php/php5.5.14/lib/php:/Applications/MAMP/htdocs/uploads"
So from all the things that I have read, and I've tried them, nothing is working. something in my syntax must be off??? what aren't I getting??
You forgot a trailing slash in your location value.
$location = 'uploads/';