?
Solved

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

Posted on 2009-04-27
3
Medium Priority
?
218 Views
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/www.foreveryoungchiro.ca/web/upload_test, but it just never uploads to me 'upload_test' folder?

Can anyone see what is wrong?
<?php
if (array_key_exists('upload', $_POST)) {
// define constant for upload folder
define('UPLOAD_DIR',  '/home/sites/www.foreveryoungchiro.ca/web/upload_test/');
 
 
// 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: 
 
Array
(
    [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

0
Comment
Question by:jrcygnus
3 Comments
 
LVL 6

Accepted Solution

by:
basic612 earned 1200 total points
ID: 24247068
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.
0
 
LVL 14

Assisted Solution

by:shobinsun
shobinsun earned 800 total points
ID: 24247589
Hi,

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.

0
 

Author Comment

by:jrcygnus
ID: 24253040
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.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses
Course of the Month13 days, 14 hours left to enroll

807 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