Public Image Upload (3 posts)

  1. RightCoastRipper
    Posted 4 years ago #

    Hi all. First post here, and newb to php and the backend of wordpress

    I am creating an html form that users can complete a few text fields and upload an image.

    I have a php script that sends the text fields and the file location to a MySQL database. This script also tries to upload the picture to my uploads directory, but it doesn't work. I am using exec-PHP to run the script on a static page.

    I am using wp_upload_dir() and move_uploaded_file() to upload the file to my upload directory.

    //This is the directory where images will be saved
     $upload_dir = wp_upload_dir();
     $target = $upload_dir . basename( $_FILES['image']['name']); 
    //Writes the photo to the server
     if(move_uploaded_file($_FILES['image']['tmp_name'], $target))
     //Tells you if its all ok
     echo "The file ". basename( $_FILES['image']['name']). " has been uploaded, and your information has been added to the directory";
    echo $uploads['path'] . '<br />';
    echo $uploads['url'] . '<br />';
    echo $uploads['subdir'] . '<br />';
    echo $uploads['basedir'] . '<br />';
    echo $uploads['baseurl'] . '<br />';
    echo $uploads['error'] . '<br />';
     else { 
     //Gives and error if its not
     echo "Sorry, there was a problem uploading your file.";

    When I submit the form, the MySQL database is populated(query not shown), and I get the true response when I ask if the file was uploaded, BUT there is no information in $uploads

    I am thinking the image might need to be resized or something.

    Any help is appreciated. Thank you

  2. RightCoastRipper
    Posted 4 years ago #

    ok got it to upload to the directory. how do i store so that wordpress knows its there?

  3. Tom Lynch
    Posted 4 years ago #

    There is a whole set of upload functions for WordPress which you could use instead for this, I would suggest looking at how WordPress handles its own uploads and trying to replicate that.


Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.