Forum Moderators: coopster

Message Too Old, No Replies

Upload on localhost problem

Path or permission issue under Windows?

         

Notawiz

9:43 am on Sep 7, 2004 (gmt 0)

10+ Year Member



Most of us will remember the neat image upload and thumbnail generation script posted here by Birdman.

To make a long story short, I tried the script on the hosting webserver, and after altering a bit the paths and chmod of the target directories, the script ran like a charm.

But no matter how I change things, on my localhost config (Apache + PHP + Mysql = EasyPHP pack on Windows XP pro) I always end up with this error:
Warning: Unable to create 'http://the/path/to/the/directory/images/': Invalid argument in c:\program files\easyphp\www\the\path\to\the\script\loademup.php on line 55
followed by errors about the script not being able to handle and edit the file (logical after that very first error).

In the error log of Apache, it states:
File does not exist: c:/program files/easyphp/www/images/thumbs/
As you can see, the whole tree structure between the server root /www/ and /images/thumbs/ is missing.
I get the same error even if I manually create a folder /images/ at the /www/ root.
And the same Apache error is stated no matter what the path to the upload directory was mentioned in Birdman's script?

Any idea how to make this work locally on my apache localhost server on my @!##$§ Windows XP box?

Notawiz

tomda

10:33 am on Sep 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I also run the EasyPHP.

Some tips, I usually have a conf folders where I have all important variable or include which may change depending if your are in localhost or in Internet. Then, the first variable I call in everypage is my switch variable (switch=0 means localhost and switch=1 means web). The good thing about this is that I just need to change the switch before uploading it on the net (and I do need to open every file to change the config). Hope you understand me. Just for you to understand, see how I set my include path and docroot using a switch variable. Try to do this, it will save you lot of time.


include_once ("switch.php");

$DOCUMENT_ROOT=$_SERVER['DOCUMENT_ROOT'];

if ($switch=="0") {$url_loc="localhost/www.example.com/";
$url_root=str_replace($DOCUMENT_ROOT , "http://".$url_loc."", $DOCUMENT_ROOT);
session_register('url_root'); $_SESSION['url_root']=$url_root;

//SET INCLUDE PATH - ALL PHP
ini_set("include_path", ".;D:\EasyPHP2\EasyPHP1-7\www\www.example.com\include");

} else {

$url_loc="www.example.com/";
$url_root=str_replace($DOCUMENT_ROOT , "http://".$url_loc."", $DOCUMENT_ROOT);

session_register("url_root"); $_SESSION["url_root"]=$url_root;

/* NO INCLUDE PATH - ALREADY SET */
}

Regarding your problem, open your phpinfo in localhost and see what is your include_path and do not use http:// to read/open include. You may also notice that my include path is .;D:\ , I never understood why .; are there.

I can't tell you more. Ah yeah, you should put the pic in the temp files before copying it in your images folder.

Notawiz

11:22 am on Sep 7, 2004 (gmt 0)

10+ Year Member



Hello Tomda,

I'm not sure about the use of changing the include path, since Birdman's script does not need any include routine.

Before posting my message I already checked my local php.ini file and noted that the correct settings were there regarding file uploads:
file_uploads= On
upload_tmp_dir="C:\Program Files\EasyPHP\tmp\"
upload_max_filesize = 2M

When no specific temp path is defined, PHP uses this default settings.

When I check the content of the temp folder, I only find my session files, not the upload-test files, but I guess that because of the failure of the upload process, the temp files are deleted at completion/end of the script.

As for the path of the upload target dir, I tried all kind of syntaxes, but posted only one as example of the type of error message (the message is always the same, no matter what absolute or relative path is defined in the script).

So I'm still struck :-(

Notawiz

tomda

11:43 am on Sep 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You are right about the include path. There are no include called in the Birdman script. Sorry for that.

I went to my old GD gallery script (the one I did without include) and it works great (easyphp 1.7 and XP). Create the following files in your root www / script / uploadGD_pic / images / thumbs

Copy and paste the following script, save it in your uploadGC_pic folder and run it - it should be OK otherwise let me know the error you get.

NOTA BENE
*********
1/you may need to change the $uploaddir as Easyphp is in D:
2/note that my picture are automatically name lm

It should copy the pic in the images folder and make the thumbnail in the thumbs.

Try it and let me know


<?
$server="localhost"; $user="root"; $pass=""; $database="test"; $table="pics";
$dbh= mysql_connect("$server","$user","$pass") or die ("Unable to connect server");
$switch="0";
$db_select=mysql_select_db("$database") or die ("Unable to get table");
$sizelimit = "42000";
$uploaddir = "D:/EasyPHP2/EasyPHP1-7/www/script/uploadGD_pic/images/";
$serverdir = "http://localhost/script/uploadGD_pic/images/";

function GetSize($s) {if ($s <= 1024) return $s." bytess"; else if ($s <= 1048576) return $s = round($s/1024,0)." Kb"; else if ($s <= 11559501824) return $s = round($s/1048576,0)." Mb";}

?>

<html><head><title>Submit your pictures</title>
</head><center>

<? echo "<table cellpadding=0 cellspacing=0 width=765><tr><td width=200 rowspan=2 ></td><td height=26 ></td></tr><tr><td width=580>&nbsp;</td></tr><tr><td height=5 colspan=4></td></tr></table>";?>

<table cellpadding=0 cellspacing=0 width=765>
<tr><td align=right></td><td bgcolor="#F3B443" align=center><span id=dTb><b>SUBMIT YOUR PICTURES</b></span>&nbsp;&nbsp;<span id=dSb><font color="#A05552"><? echo date("D, d M Y") ;?></td><td></td></tr><tr><td colspan=3><br><br>

<form method="post" action="" enctype="multipart/form-data" >
<input type="file" name="imagefile" style="font-family: arial; font-size:11; color:#A05552; background:#F4C165; font-weight: bold;">
<input type="submit" name="Submit" value="Submit" style="font-family: arial; font-size:11; color:#A05552; background:#F4C165; font-weight: bold;">

<?
if(isset($_POST['Submit'] )) {
if ($_FILES['imagefile']['type'] == "image/pjpg" ¦¦ $_FILES['imagefile']['type'] == "image/pjpeg") {
if ($_FILES['imagefile']['size'] >= $sizelimit) {$size = GetSize($_FILES['imagefile']['size']);
echo "<br><span id=dSc>The file you are attempting to copy is too heavy (<b>".$size."</b>).<br>Please, make sure the file is less than <b>"; $sizelimit = GetSize($sizelimit); echo "".$sizelimit."</b><br>Thank you</span>";}

else {
$size = GetSize($_FILES['imagefile']['size']);


/* ****************************************** */
/* YOU NEED THIS ONLY IF YOU WANT TO GENERATE A NEW ID FROM YOUR DATABASE */
/* ****************************************** */
/* $sql = "SELECT pic_id FROM pics ORDER BY pic_id DESC LIMIT 1";
$result = mysql_query($sql);
while($i = mysql_fetch_array($result)){
$new_id = $i['pic_id'] + 1;} */
/* ****************************************** */
/* OTHERWISE */
$new_id= 1;
/* ****************************************** */

copy ($_FILES['imagefile']['tmp_name'],"".$uploaddir."".$new_id. ".jpg") or die ("Could not copy");

echo "<br><span id=dSc>";
echo "Name: ".$new_id. ".jpg - ";
echo "Size: ".$size." - ";
echo "Type: ".$_FILES['imagefile']['type']."<br>";
echo "Large size path: ".$uploaddir."".$new_id. ".jpg<br>";
echo "Copy Done....</span>";?>

<?
$sql = "INSERT INTO `pics` ( `pic_id` , `pic_name` , `descrip` )VALUES ('NULL', NULL , NULL);";
mysql_query($sql);

$new_thumb = "thumbs/" .$new_id. ".jpg";
$sourcefile = "".$uploaddir."".$new_id. ".jpg";
$picsize = getimagesize("$sourcefile");
$source_x = $picsize[0];
$source_y = $picsize[1];

$dest_x = $source_x*16/100;
$dest_y = $source_y*16/100;

$targetfile = "$uploaddir$new_thumb";
$jpegqual = 75;
$source_id = imagecreatefromjpeg("$sourcefile");
$target_id = imagecreatetruecolor($dest_x, $dest_y);
$target_pic = imagecopyresized($target_id,$source_id,0,0,0,0,$dest_x,$dest_y,$source_x,$source_y);
imagejpeg($target_id,"$targetfile",$jpegqual);
?>

<br><br><img src="<? echo "".$serverdir."".$new_thumb.""?>"><br><br>
Name: <? echo "" .$new_id. ".jpg"?><br><br>
Thumbnail path: <? echo "".$targetfile."".$new_id. ".jpg<br>";

} }
else {
echo "<br><span id=dSc>The file (<b>".$_FILES['imagefile']['name']."</b>) you are attempting to copy is not in a good format.<br>Please, make sure that your file is a <b>jpg/jpeg</b> format"; }}
?>
</body>
</html>

Notawiz

1:49 pm on Sep 7, 2004 (gmt 0)

10+ Year Member



Hello Tomda,

Thank you for your help.

With a bit of tweaking, I was able to make this script work on localhost, even with the autonumbering through the mysql statements and linking to the normal size picture (had to define also a imagedir variable for that).

I will now be able to make this code snippet part of a complete user profile upload procedure.

Notawiz