Jump to content

PHP Uploading... Novice..


George Botley

Recommended Posts

Hello,

 

I have written a PHP upload script.. all is well, so far... apart from the moving of the file at the very end of the script.

 

Here's my script..

 

<?
/* 

This script handles the uploading of a users photos to the display screen slideshows.

    1. Collects data from uploaded image
    2. Checks to see if database table exists for the screen in question.
    2. Inserts record into database should a table exist. Otherwise, kill script.
    3. Takes ID of inserted record from the database
    4. Renames photo to the ID of the inserted record
    5. Moves photo to the directory holding the images for the screen
    6. Modifies entry inserted above to include new image location
    
*/

//Config
include_once "../../includes/config/config.php";

//Retrieve the screen the user is uploading to
$area = $_POST["area"];

//Check to see if screen exists
$query = "SELECT * FROM screen_areas WHERE area='$area'";
$query = mysql_query($query);
    $num_rows = mysql_num_rows($query);
    if($num_rows=="0") { 
        die("Photo upload could not be completed. Screen not found in database. (Error 3)"); 
    }

//Image Information
$title = $_POST["title"];
$description = $_POST["description"];

//Simplify Image Data Array
$image = $_FILES["image"];
$name = $image["name"]; //Photo Name
$temp = $image["tmp_name"];
$extension = end(explode('.', $name));

//New Photo Location
$new_location_directory = "/screens/images/$area";
$new_location = "$new_location_directory/$name";

//Check if new location (directory) exists
$is_dir = is_dir($new_location_directory);
    if($is_dir=="FALSE") {
        die("Photo upload could not be completed. Screen directory could not be located. (Error 4)"); 
    }

//Insert record into database for this image
$query = "INSERT INTO screen_data (area, title, description, location) VALUES ('$area', '$title', '$description', '$new_location')";
$query = mysql_query($query) or die(mysql_error());
    //Get ID of inserted record
    $query = "SELECT * FROM screen_data WHERE title='$title' AND description='$description' AND location='$new_location'";
    $query = mysql_query($query);
        while($row=mysql_fetch_array($query)) {
            $id = $row["id"];    
        }
        
//Rename File
$name_rename = "$id";
$name_rename .= ".";
$name_rename .= "$extension";

//New Location after Renaming
$new_location = "$new_location_directory/$name_rename";
    
//Move Photo
if(move_uploaded_file("$temp", "$new_location")) {
    echo "The file ".  basename($name).  " has been uploaded";
}

 

And here is the error returned to me:

 

Warning:  move_uploaded_file(/screens/images/conference centre/23.png) [function.move-uploaded-file]: failed to open stream: No such file or directory in /Users/George/Desktop/Torindul/Customer Accounts/1035 The Gryphon School/Display CMS/Website/includes/functions/upload.php on line 69

 

Warning:  move_uploaded_file() [function.move-uploaded-file]: Unable to move '/Applications/MAMP/tmp/php/phpK8VJYe' to '/screens/images/conference centre/23.png' in /Users/George/Desktop/Torindul/Customer Accounts/1035 The Gryphon School/Display CMS/Website/includes/functions/upload.php on line 69

 

Any ideas as to why this may be occurring?

 

Thanks in Advance,

George.

 

P.S I have CHMOD'd all directories to 755 where required.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.