Help - Search - Member List - Calendar
Full Version: Image uploading
WorkTheWeb Forums > Web Hosting Help > PHP Help
Support our Sponsors!
jakek
I would like to upload images from a form on a site. I have a php script that works locally but does not on the live site. Is this some sort of permissions issue? script code:

CODE

<form action="<?php echo $PHP_SELF; ?>" method="post"enctype="multipart/form-data" name="form1">
<input name="filename" type="file" id="filename"><br>
<input name="Upload" type="submit" id="Upload" value="Upload">
<input name="MAX_FILE_SIZE" type="hidden" id="MAX_FILE_SIZE"value="50000">
</form>


CODE

<?php
   if($_POST['Upload'] == "Upload") {
       $originalFileName = $_FILES['filename']['name'];
       $tempFileName = $_FILES['filename']['tmp_name'];
       $siteRoot = "/test";
       $newPath = $siteRoot . "/images/" . $originalFileName;
       umask(0);
       move_uploaded_file($tempFileName, $newPath);
       system("chmod 755 $newPath");
   }
?>
phpfreak
jakek,

You are defining $siteRoot as /test which means the root of the file system and a directory underneath it called 'test' which you don't have access to create. Instead, you should use something like:

CODE

$siteRoot = $_SERVER['DOCUMENT_ROOT'].'/test';


That will put it under /home2/username/public_html/test/

Next, you need to make sure that you have permissions for the webserver to write to this 'test' directory. You can use the file manager in cPanel or your FTP client.

Please let us know how that goes!


jakek
QUOTE(phpfreak @ Feb 28 2005, 05:00 AM)
jakek,

You are defining $siteRoot as /test which means the root of the file system and a directory underneath it called 'test' which you don't have access to create. Instead, you should use something like:

CODE

$siteRoot = $_SERVER['DOCUMENT_ROOT'].'/test';


That will put it under /home2/username/public_html/test/

Next, you need to make sure that you have permissions for the webserver to write to this 'test' directory. You can use the file manager in cPanel or your FTP client.

Please let us know how that goes!
*



I changed the permissions and corrected the code and it's fine now. Thanks.
phpfreak
QUOTE(jakek @ Feb 28 2005, 07:06 PM)
I changed the permissions and corrected the code and it's fine now. Thanks.
*



No problem, I'm glad it helped!

PHP Help | Linux Help | Web Hosting | Reseller Hosting | SSL Hosting
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2006 Invision Power Services, Inc.