473,399 Members | 4,177 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Problem with uploading images to my localhost

Hello, so here is my code for this add score, images php. but when i click the submit bottom the images won't go to the pointed folder thats under my website root folder.

1st question: could this be a permission limited on the read and write of images? i'm using mac osx

2nd question:Is that why i keep getting echo"please enter all infor" from the if statement because the images is not correctly upload?

3th question: on define(''GW_UPLOADPATH','/Library/WebServer/Documents/gw/images/'); do i have to type in the location of where the images folder is or the DW will know exactly where to save it since the folder is in the same as the web folder

thank you for your time



Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. <?php
  4. define('GW_UPLOADPATH','/Library/WebServer/Documents/gw/images/');
  5.  
  6. if(isset($_POST['submit'])){
  7.     $name=$_POST['name'];
  8.     $score=$_POST['score'];
  9.     $screenshot=$_FILES['screenshot']['name'];
  10.     echo "filename is $screenshot";
  11.  
  12. if(!empty($name)&& !empty($score)){
  13.     $target=GW_UPLOADPATH.$screenshot;
  14.     echo "Moving file to $target";
  15.  
  16.     if(move_uploaded_file($_FILES['screenshot']['tmp_name'], $target)){
  17.  
  18.         $dbc=mysqli_connect('localhost','***','****','guitar');
  19.  
  20.         $query="insert into guitarwars values(0, now(),'$name','$score','$screenshot')";
  21.         mysqli_query($dbc, $query);
  22.  
  23.         echo'<p>Thankys for adding your new high score!</p>';
  24.         echo'<p><strong>Name:</strong>'.$name.'<br/>';
  25.         echo'<strong>Score:</strong>'.$score.'<br/>';
  26.         echo'<img src="'.GW_UPLOADPATH. $screenshot.'" alt="Score image"/></p>';
  27.         echo'<p><a href="index.php"&lt;&lt; Back to high scores</a></p>';
  28.  
  29.         $name="";
  30.         $score="";
  31.  
  32.         mysqli_close($dbc);
  33. }
  34. else{
  35.     echo'<p class="error">Please enter all the information.</p>';
  36. }
  37. }
  38. }
  39. ?>
  40.  
  41. <form enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['php_self'];?>">
  42. <input type="hidden" name="MAX_FILE_SIZE" value="32768" />
  43. <label for="name:">Name:</label>
  44. <input type="text" id="name" name="name" value="<?php if(!empty($name)) echo $name;?>"/>
  45. <br/>
  46. <label for="score">Score:</label>
  47. <input type="text" id="score" name="score" value="<?php if(!empty($score)) echo $score;?>"/>
  48. <br/>
  49. <label for="screenshot">Screen shot:</label>
  50. <input type="file" id="screenshot" name="screenshot"/>
  51. <hr/>
  52. <input type="submit" value="Add" name="submit"/>
  53. </form>
  54.  
  55.  
May 9 '11 #1
2 2845
code green
1,726 Expert 1GB
What errors are you getting?
Where is the working directory in relation to
Expand|Select|Wrap|Line Numbers
  1.  define(''GW_UPLOADPATH','/Library/WebServer/Documents/gw/images/');
May 10 '11 #2
hello green light. i just figure it out, with help from my buddy. my problem was i didn't give the permission for target folder. my solution was:

1. go to terminal (i use mac)

2. go under my gw (web folder)
for some reason i can't not use the original root name and the group name, so i change it to www:www

3. sudo chown www:www images/ (hit enter, enter password and boom. Is done and done.)

but i have one more question, why can't i use the default root name and the group name? instead i have to change it to www:www?
May 10 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: laredotornado | last post by:
Hi, I'm using PHP 4 and I am submitting some images in a form with <form name=addProductForm enctype="multipart/form-data" method=post action="add_product_response.php"> <input type=file...
2
by: JonChart | last post by:
Hi all, I would like to know ho to validate a file name when uploading via asp. I need to upload 2 images and the file names must be the same... 1) browse for 1st image. 2) image path and...
3
by: Gavin | last post by:
I need some help, I need the code to allow people that visit my website to be able to upload pictures to a file on my web server. I have been able to get close, but not quite there yet. Set fso...
1
by: joe | last post by:
Any articles relating with Uploading images files to server and resize the image by asp.net 2.0
1
by: Nerry | last post by:
Hello everyone, I have ASP webpages, but I have a problem uploading my images via ftp, keep getting an error: An error occurred copying a file to the ftp server. Make sure you have permissions...
0
by: LizB | last post by:
Hi guys, I would appreciate very much any help that anybody can give me with the following problem I have. I am trying to upload images using PHP move_uploaded_file, but for some reason the...
4
by: tddeffner | last post by:
Hey, I was wondering if you guys could help me out. I need to find a way to automatically generate thumbnails as seperate images when uploading. I keep hearing that JavaScript can do it. Anyone...
1
pezholio
by: pezholio | last post by:
Hi, It seems that every time I put together a new script to upload a file I always have problems, here's the latest one: I've got a form with two file input fields, when I submit the form,...
7
by: nwclark | last post by:
Ok... I have a noobie issue. I am trying to upload a photo to specific directory on my server. (this is working correctly with the code below). However, I am also trying to rename the file and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.