George Botley Posted October 26, 2010 Share Posted October 26, 2010 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. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted October 26, 2010 Share Posted October 26, 2010 move_uploaded_file(/screens/images/conference centre/23.png) [function.move-uploaded-file]: failed to open stream: No such file or directory there is no such directory, '/screens/images/conference centre/' is that the full path from server root? Quote Link to comment Share on other sites More sharing options...
George Botley Posted October 26, 2010 Author Share Posted October 26, 2010 Does this have to be from server root then? or can it not be in relation to the script running the function? Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted October 26, 2010 Share Posted October 26, 2010 I would try $path_to_upload_dir = $_SERVER['DOCUMENT_ROOT'] . "/screens/images/conference centre/"; move_uploaded_file($path_to_upload_dir . "23.png"); Quote Link to comment Share on other sites More sharing options...
George Botley Posted October 26, 2010 Author Share Posted October 26, 2010 That works fine!! Do you know how to get the width and height of an uploaded image and resize it keeping constrained dimensions? Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.