Hi everyone,
I'm using move_upload_function for uploading file. I works fine on localhost but, it doesn't work on live server.
Thank in advance..
Good catch by and the correct fix from — the live site failed because the web process did not have write access to the uploads folder, and was right to warn about making a folder world‑writable. Granting public write bits fixes the symptom but opens a security hole. Prefer giving write access only to the webserver user or to a group the webserver runs under.
Practical, safer approach (replace names with the ones on the server):
# make the webserver user/group own the upload folder
sudo chown -R www-data:www-data /full/path/to/uploads
# give owner write and let group/others read/execute where appropriate
sudo find /full/path/to/uploads -type d -exec chmod 750 {} \;
sudo find /full/path/to/uploads -type f -exec chmod 640 {} \; If chown isn't possible (shared hosting), 755 on directories will usually work but avoid 777. After upload, set uploaded files to non‑executable (0644) so they cannot be run on the server.
If problems persist, check these common live‑server issues not shown in the thread:
method="post" and enctype="multipart/form-data".$_FILES['image']['error'] or log the whole $_FILES array to capture PHP upload errors.file_uploads, upload_max_filesize, post_max_size) via phpinfo() or php -i.upload_tmp_dir exists and is writable, and that open_basedir or SELinux/AppArmor aren’t blocking writes (on SELinux use chcon -t httpd_sys_rw_content_t /path/to/uploads when appropriate).Security notes: validate file type and size, sanitize filenames, store uploads outside the webroot when possible, and serve them through a script. These steps keep uploads functional while avoiding the risks of a world‑writable directory.
Jump to Post— Member #120589show your code. Is the destination directory writable?
Jump to Post— pzuurveen 90check if the directory orig_img/ on your server is writeble by apache
show your code. Is the destination directory writable?
if ($_FILES['image']['name'] != "")
{
$ext = explode(".",$_FILES['image']['name']);
$extension = strtolower($ext[1]);
if ($extension =="jpg" || $extension =="jpeg" || $extension =="png" || $extension == "gif")
{
include("class/resize-class.php");
$action = "auto";
$width_thumb = 148;//output for portrait 119px && for landscape it is 148px
$height_thumb = 148;//output for portrait 148px && for landscape it is 128px
$width_medium = 340;//output for portrait 273px && for landscape it is 340px
$height_medium = 340;//output for portrait 340px && for landscape it is 296px
$file_name = time().".".$extension;
$target_path = './orig_img/'.$file_name;
if(move_uploaded_file($_FILES['image']['tmp_name'], $target_path))
{
echo "Image Uploaded Successfully!!";
}//EO if(move_uploaded_file($_FILES['upload']['tmp_name'], $target_orig))
else
{
$error_msg[] = "Problem Occured While uploading image";
}
}//EO if ($extension =="jpg" || $extension =="jpeg" || $extension =="png" || $extension == "gif")
else
{
$error_msg[] = "Please Upload only jpg, jpeg, png or gif formats for image";
}
}//EO if ($_FILES['image']['name'] != "") check if the directory orig_img/ on your server is writeble by apache
Thx my freind. The folder was not having write permission. I gave read, write, execute permission to all options i.e. Owner Permissions, Group Permissions & Public Permissions
Now, its working. You saved my day. Thanks a lot
//EDIT
Solution posted as I was typing:
show your code. Is the destination directory writable?
As I thought.
Please mark as solved.
Thx my freind. The folder was not having write permission. I gave read, write, execute permission to all options i.e. Owner Permissions, Group Permissions & Public Permissions
if you set write permisons to public that mean that ANYONE can write files to dir.
You don't want that.
You mean that, I should give write permission to only Owner & Group?
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.