Click here to Skip to main content
15,902,763 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
PHP
<?php
    //this function returns a random 5-char filename with the jpg extension
    function randomFileName()
    {
       $length = 5;
       $characters = 'abcdefghijklmnopqrstuvwxyz';
       $string = '';
       for ($p = 0; $p < $length; $p++) {
          $string .= $characters[mt_rand(0, strlen($characters))];
       }
       return $string . '.jpg';
    }
    //create the random filename string and uploads target variables
    $randomString = randomFileName();
    $target = 'http://pindots.com/admin/pin/upload/';
    $target = $target . $randomString;
    if(move_uploaded_file($_FILES['media']['tmp_name'], $target))
    {
        //output the location to our image
        echo 'http://pindots.com/admin/pin/upload' . $randomString;
    }
    else
    {
        echo "false";
    }
?>
Posted
Comments
joshrduncan2012 6-Mar-13 9:11am    
What kinds of errors are you getting? "not working" doesn't help us. Please improve question and provide more info (including line of where error is pointing to).

1 solution

Have you ever looked at the ove_uploaded_file[^] manual page? I think you haven't. Because that one is for something else. See: uploaded. It is for moving files uploaded on php side from it's temporary location to it's persistent location on the same side as the php code runs. Of course, it can by a remote location, but only if that one is mounted locally.
So, you won't be able to upload that file to a server via http, even a file system that is exposing itself via http and you could access it from windows explorer - simply because it is out of scope of php, and probably of the web server service itself too (this stands for Linux too, not only for windows).

So if the url you specified is actually a local path on the server, try to specify a local folder path instead of a virtual path that you see from client side. If it is a location remote to the server running the php script, you will need other means to copy the file there.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900