Pierce McGeough
Pierce McGeough

Reputation: 3086

Why is move_uploaded_file not working for me

I am using mysqli procedural programming and the move_uploaded_file isnt working for me now. I am working locally now so I have all privileges needed.

if(move_uploaded_file($_FILES['image']['tmp_name'], $target)){ 
    redirectTo($settings['siteDir'] . 'admin/cpanel/');
}

I have never had problems before now. Is it the mysqli that is messing things up? These are the errors I am getting

Warning: move_uploaded_file(http://localhost/websites/mugendo.ie/images/uploads/mai.jpg) [function.move-uploaded-file]: failed to open stream: HTTP wrapper does not support writeable connections in D:\xampp\htdocs\websites\mugendo.ie\admin\addnews.php on line 29

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'D:\xampp\tmp\php1498.tmp' to 'http://localhost/websites/mugendo.ie/images/uploads/mai.jpg' in D:\xampp\htdocs\websites\mugendo.ie\admin\addnews.php on line 29

Upvotes: 1

Views: 6227

Answers (1)

AD7six
AD7six

Reputation: 66169

$target should be a path

The second argument for move_uploaded_file is expected to be a path. The error message reads:

Unable to move ... to http://localhost/websites/mugendo.ie/images/uploads/mai.jpg

As such, right now $target is a url. Provide a valid file path for $target and it will work, or provide a different error message e.g.:

$target = 'D:\xampp\htdocs\websites\mugendo.ie\images\uploads\mai.jpg';
if(move_uploaded_file($_FILES['image']['tmp_name'], $target)){ 
    redirectTo($settings['siteDir'] . 'admin/cpanel/');
}

Be sure to read the error log if it fails - the error message will say exactly what needs correcting to succeed.

Upvotes: 2

Related Questions