Jump to content

upload file path question


justAnoob

Recommended Posts

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?

Link to comment
Share on other sites

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)?

Link to comment
Share on other sites

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();
?>

Link to comment
Share on other sites

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.)

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.