• Graham

    (@aerin)


    I’m developing a simple plugin that manages logo uploads.

    The plugin has a form that allows the user to upload and image from their PC. This works fine.

    But I want to save the uploaded file to the server. This is where it all comes unstuck.

    move_uploaded_file seems to be an ideal solution but WP throws a wobbly:

    Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move ‘/tmp/phpCnl49u’ to ‘http://testblog.co.uk/wp-content/themes/themename/images/28d0a66d7f8fddb23b577b89ee2c68d5.jpg’ in /home/wwwtestb/public_html/wp-content/plugins/logo-uploader/logo-uploader.php on line 68

    Line 68 is:

    if (move_uploaded_file($_FILES['lu_logo']['tmp_name'], $target_path . $filename)) {

    Really stumped on this one. It’s not a permissions thing because it fails if I try to upload to the uploads folder as well.

    Any thoughts?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hello aerin,

    I am facing the same problem now ; but the problem is with the parameter. As you might know ‘move_uploaded_file’ doesn’t support any ‘http://’ links to move the files. So you are getting the problem. I am also looking for a way around as I am a newbie in WP-Plugin development. Do let me know if you found out anything.

    Thread Starter Graham

    (@aerin)

    It took a while but I did get it to work. The line I used was:

    move_uploaded_file($_FILES['logo_name']['tmp_name'], TEMPLATEPATH .'/images/'. $_FILES['logo_name']['name']);

    The best way to see the solution is to go get the plugin: http://wordpress.org/extend/plugins/logo-manager/

    Okay , but my problem is that I am uploading it from a plugin in the admin part. I want the files to get uploaded in the ‘wp-content/uploads’ folder. So any idea?

    Just got it working.

    $path_array  = wp_upload_dir();
    		$path = str_replace('\\', '/', $path_array['path']);
    		$old_name = $_FILES["image_upload_path"]["name"];
    		$split_name = explode('.',$old_name);
    	 	$time = time();
    		$file_name = $time.".".$split_name[1];
    		move_uploaded_file($_FILES["image_upload_path"]["tmp_name"],$path. "/" . $file_name);

    working fine for me on local server

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Using move_uploaded_file in a plugin’ is closed to new replies.