PHP: How do I get an uploaded file from the temp folder to an actual ('upload_test') folder?

Posted on 2009-04-27
Last Modified: 2012-05-06
Hi ,
I can test my script below on the local server, but it does not work on the live site. My host told me the directory is /home/sites/, but it just never uploads to me 'upload_test' folder?

Can anyone see what is wrong?

if (array_key_exists('upload', $_POST)) {

// define constant for upload folder

define('UPLOAD_DIR',  '/home/sites/');

// move the file to the upload folder and rename it

move_uploaded_file($_FILES['image']['tmp_name'], UPLOAD_DIR.$_FILES['image']['name']);



As seen below it successfully loads to the tmp folder but how do I redirect it for stay permanently on a site folder?

Upload image: 



    [image] => Array


            [name] => ist2_1566514-grandfather-with-grandson-under-cloudfield.jpg

            [type] => image/pjpeg

            [tmp_name] => /tmp/phpKRNOgP

            [error] => 0

            [size] => 48660



Open in new window

Question by:jrcygnus
    LVL 6

    Accepted Solution

    can you check the permissions on the upload_test folder?

    for simplicity make it 777 for now and see if php is able to move the folder there

    you could put some permissions error checking / messages in your script to handle this better in the future.
    LVL 14

    Assisted Solution


    You should have 777 permission to the uploaded directory . I fyou didnt set that use the foloowing code for that:

    chmod("/somedir/somefile", 777);

    Then try.

    hope this will help you.


    Author Comment

    Thanks guys!
    I was not quite sure what 777 was, but I looked it up and began to understand about permission settings.
    I am going to add more script to check for file types and size, but I just wanted to keep it simple for now until I could find out why nothing was uploading.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
    Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
    Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
    Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now