$target_path = "/public_html/user_images/";
//$target_path = realpath(user_images(getcwd()))
$targetpath = basename( $_FILES['uploadedfile']['name']);
$target_path = $target_path . $targetpath;
move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path);
//echo "Image". basename( $_FILES['uploadedfile']['name']). " has been successfully uploaded.";
$user_img = $target_path;
The leading /
slash takes you all the way to the root of your server. You need to either use the full path (which on your server might be eg /home/yourdomain.com/public_html/images/
, or otherwise a path that is relative to the script you're running, eg '../images/'
if your upload script were in ./public_html/codes/
, or simply './images/
if your script is in ./public_html/
.
Add error reporting to the top of your file(s) which will help find errors.
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// rest of your code
Sidenote: Error reporting should only be done in staging, and never production.
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.