简体   繁体   中英

Upload File is Prefixing designated folder's name, and ends up outside of that folder

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??

您忘记了位置值中的尾部斜杠。

$location = 'uploads/';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM