简体   繁体   中英

SERVER:move_uploaded_file doesn't work in freewebhostingarea

Have anyone experiant this freewebhostingarea. I've already check everything and it's work well when i run it in my server. But when i run it into freewebhostingarea. It's fail to move uploaded file to dir.

I think it's about permission of directory. So i set it in to 777. Any Idea?

here is my code

$m_id=$_COOKIE['m_id'];
$image_type=$_POST['image_type'];
$upic="u_".$image_type."_pic";
$valid_formats = array("jpg", "png", "bmp","jpeg");
   if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST")
{
    $fileinfo=pathinfo($_FILES['photoimg']['name']);
    $size = $_FILES['photoimg']['size'];
if(isset($fileinfo['extension']))
{
    $ext=strtolower($fileinfo['extension']);
if(in_array($ext,$valid_formats))
{
if($size<(5*1024*1024)) // Image size max 1 MB
{
    $name ="uploadimg.".$ext;
    $tmp = $_FILES['photoimg']['tmp_name'];
if(move_uploaded_file($tmp,"../user/$m_id/$name"))
{
    BLAH BLAH 

    exit("<script>window.location='../user_page_update.php?u_id=$m_id';</script>");
}

else
    exit("<script>alert('failed');window.location='../user_page_update.php?u_id=$m_id';</script>"); 
}
else
    exit("<script>alert('Image file size max 2 MB');window.location='../user_page_update.php?u_id=$m_id';</script>");   
}
else
    exit("<script>alert('Invalid file format..');window.location='../user_page_update.php?u_id=$m_id';</script>");  
}
else
    exit("<script>alert('Please select image..!');window.location='../user_page_update.php?u_id=$m_id';</script>"); 
    exit;
}

In particular for www.freewebhostingarea.com , by default, the permissions are low for any folder in the root. If you want to create a folder (let's say "images") in which to save a file through a form, firstly you should login to freewebhostingarea.com/ftp/ and then there is a little button in the top-right corner, named CHMOD. Firstly select your folder (by clicking in the little box near it), and then click on CHMOD and turn on all the boxes being there. Doing so, you will change the permissions (only for that folder) to 777 (meaning "full access"). That's all. And then, the command move_uploaded_file($_FILES["file"]["tmp_name"],"/home/vhosts/~your site name ~/images/" . $_FILES["file"]["name"]); will work ok.

I hope this is useful for other people having the same dilemma.

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