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
https://forums.phpfreaks.com/topic/216884-php-uploading-novice/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.