justAnoob Posted January 25, 2010 Share Posted January 25, 2010 I am having trouble uploading a picture to a directory on my server. First off, i have 2 domain names, domain 1 and domain 2 With domain 1 i have the exact same upload script that I am trying to make work with domain 2. Domain 1 works great. The problem with domain 2 is it cannot find the directory that i wish to upload the image to. $newname="userimages/trackimages/".$image_name; it is telling me that the directory does not exist. I know it is there and yes I did make the directory writable. Anyone know what is going on? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted January 25, 2010 Share Posted January 25, 2010 The actual error message and the code would help. There are at least a half-dozen different things that could go wrong with an upload script or with a directory path that could cause an error that would look like it is a path problem. Are you sure that relative to the main script that is running that the userimages/trackimages/ path exists with that spelling and capitalization (assuming you are on an operating system that is case sensitive)? Quote Link to comment Share on other sites More sharing options...
justAnoob Posted January 25, 2010 Author Share Posted January 25, 2010 yes, i'll post up some code after work. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted January 25, 2010 Share Posted January 25, 2010 Additional to the above reply - Are you also sure that $image_name does not contain any / characters that when combined with userimages/trackimages/ produces a path that does not exist. Quote Link to comment Share on other sites More sharing options...
justAnoob Posted January 25, 2010 Author Share Posted January 25, 2010 Here is the upload script. Like I said, on my other site it works just fine. Just on this site, it will not work. Here is on of the errors I'm getting. copy(userimages/trackimages/1264460369.jpg) [function.copy]: failed to open stream: No such file or directory (blah blah) line 57 <?php // this is my text field on my upload page // <input name="image" class="textbox" type="file" id="image" size="40" input="input" /> // yes, it is inside of a form with the right actions session_start(); include "connection.php"; $track_name = mysql_real_escape_string($_POST['track_name']); $description = mysql_real_escape_string($_POST['description']); $category = mysql_real_escape_string($_POST['category']); $created_on = mysql_real_escape_string($_POST['created_on']); define ("MAX_SIZE","1000"); function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } $errors=0; if(isset($_POST['submit'])) { $image=$_FILES['image']['name']; if($image) { $filename = stripslashes($_FILES['image']['name']); $extension = getExtension($filename); $extension = strtolower($extension); if (($extension != "jpg") && ($extension != "jpeg")) { echo 'error'; $errors=1; exit(); } else { $size=filesize($_FILES['image']['tmp_name']); if ($size > MAX_SIZE*1024) { echo 'error'; $errors=1; exit(); } $tname = time(); $image_name=$tname.'.'.$extension; $newname="mylahstone/trackimages/".$image_name; // LINE 57 $copied = copy($_FILES['image']['tmp_name'], $newname); $image_thumb=$tname.'-thumb.'.$extension; $newthumbname="mylahstone/trackimages/".$image_thumb; $width = 100; $height = 100; list($width_orig, $height_orig) = getimagesize($newname); $ratio_orig = $width_orig/$height_orig; if ($width/$height > $ratio_orig) { $width = $height*$ratio_orig; } else { $height = $width/$ratio_orig; } $image_p = imagecreatetruecolor($width, $height); $image = imagecreatefromjpeg($newname); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); imagejpeg($image_p, $newthumbname, 100); imagedestroy($image); imagedestroy($image_p); if (!$copied) { echo 'error'; $errors=1; exit(); } } } } // if everything is good, post new item for the user $mysqlcategory = $category; $imgpath = $newname; $thumb = $newthumbname; $findit = $_SESSION['who']; $result=mysql_query("SELECT id FROM members WHERE username = '$findit'"); $row=mysql_fetch_assoc($result); $user_id = $row['id']; $sql = "INSERT INTO MY_TABLE(track_name, description, imgpath, thumb, category, user_id, created_on)VALUES('$track_name','$description', '$imgpath', '$thumb', '$mysqlcategory', '$user_id', '$created_on')"; mysql_query($sql) or die(mysql_error()); // go to confirmation page if upload is completed. if(isset($_POST['submit']) && !$errors) { unset($_SESSION['toobig']); unset($_SESSION['badformat']); unset($_SESSION['notcopy']); header("location: http://www.MYSITE.com/index.php"); exit(); } mysql_close(); ?> Quote Link to comment Share on other sites More sharing options...
justAnoob Posted January 25, 2010 Author Share Posted January 25, 2010 the error is actually the directory mylahstone/trackimages/xxxxxx.jpg I changed that. Quote Link to comment Share on other sites More sharing options...
justAnoob Posted January 26, 2010 Author Share Posted January 26, 2010 so the actual directory where the images should go is mylahstone/trackimages the directory is there on my server and the permissions are set to be writable. I'm very confused here. Quote Link to comment Share on other sites More sharing options...
jamiet757 Posted January 26, 2010 Share Posted January 26, 2010 try using ../mylahstone/trackimages/ instead of mylahstone/trackimages/ Quote Link to comment Share on other sites More sharing options...
justAnoob Posted January 26, 2010 Author Share Posted January 26, 2010 hey, that did the trick. what exactly does the ".." mean? Quote Link to comment Share on other sites More sharing options...
jamiet757 Posted January 26, 2010 Share Posted January 26, 2010 I believe it means the root directory of the site, so if you are accessing a file in www.domain.com/folder/folder2 and need to pull a file from /folder, you need to put ../folder, otherwise it will look for /folder in /folder2. If that makes any sense at all. Quote Link to comment Share on other sites More sharing options...
justAnoob Posted January 26, 2010 Author Share Posted January 26, 2010 thanks for all the help. I'll do some research tomorrow. thanks again. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted January 26, 2010 Share Posted January 26, 2010 Are you sure that relative to the main script that is running that the userimages/trackimages/ path exists ... The path you were originally specifying is relative to the currently running script, as already suggested that you confirm. By using a leading ../ you are specifying a starting path one level closer to the disk root than the current script (this may or may not be the domain root of the site.) 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.