Jump to content

Recommended Posts

I have been working on this issue for about 2 days or so now.

 

I created a test file in a directory called test_folder

 

ftp-test.php

function file_delete($delete_file){

$ftp_server = "xxxxxxx.xxxxx.xxx";
$ftp_user = "xxxxxxx";
$ftp_pass = "xxxxxxx";

$conn_id = ftp_connect($ftp_server) or die("Could not connect to".$ftp_server);

$login_result = ftp_login($conn_id, $ftp_user, $ftp_pass);

ftp_chdir($conn_id, "/path/to/directory");

ftp_delete($conn_id, $delete_file);

ftp_close($conn_id);
}

$file = "1357458942-01-06-2013.jpg";
file_delete($file);

 

When I run the test file from the test directory it deletes the image. However when I run the same script on the modify page. I keep getting these errors




[indent=1][b]Warning[/b][color=#333333][font=Helvetica Neue', Arial, 'Liberation Sans', FreeSans, sans-serif][size=3]: ftp_chdir() [[/size][/font][/color][url="http://bwrummage.vacau.com/user/bwrummage.vacau.com%20/function.ftp-chdir"]function.ftp-chdir[/url][color=#333333][font=Helvetica Neue', Arial, 'Liberation Sans', FreeSans, sans-serif][size=3]]: Can't change directory to /home/a6512617/public_html/db_images/ad_images/: No such file or directory in [/size][/font][/color][b]/home/a6512617/public_html/admin/includes/core/function/general.php[/b][color=#333333][font=Helvetica Neue', Arial, 'Liberation Sans', FreeSans, sans-serif][size=3] on line [/size][/font][/color][b]145[/b][/indent]

[indent=1][b]Warning[/b][color=#333333][font=Helvetica Neue', Arial, 'Liberation Sans', FreeSans, sans-serif][size=3]: ftp_delete() [[/size][/font][/color][url="http://bwrummage.vacau.com/user/bwrummage.vacau.com%20/function.ftp-delete"]function.ftp-delete[/url][color=#333333][font=Helvetica Neue', Arial, 'Liberation Sans', FreeSans, sans-serif][size=3]]: Could not delete 1357458942-01-06-2013.jpg : No such file or directory in[/size][/font][/color][b]/home/a6512617/public_html/admin/includes/core/function/general.php[/b][color=#333333][font=Helvetica Neue', Arial, 'Liberation Sans', FreeSans, sans-serif][size=3] on line [/size][/font][/color][b]146[/b][/indent]
This is the page that i am trying to use it on

[code=php:0]<?php
include('../admin/includes/core/init.php');
include('../admin/includes/head.php');
include('../admin/includes/header.php');
include('includes/u-navigation.php'); //This page is located in the user/includes/ directory
protect_page();
?>
<script language="Javascript" type="text/javascript" src="/js/jquery.js"></script>
<script language="Javascript" type="text/javascript" src="/js/jquery.chainedSelects.js"></script>
<script language="Javascript" type="text/javascript" src="/js/jquery.preimage.js"></script>
<script language="Javascript" type="text/javascript">
$(function(){
$('#category').chainSelect('#sub-category','/js/combobox.php',
{
before:function (target) //before request hide the target combobox and display the loading message
{
$("#loading").css("display","block");
$(target).css("display","none");
},
after:function (target) //after request show the target combobox and hide the loading message
{
$("#loading").css("display","none");
$(target).css("display","inline");
}
});
});

$(function(){
$("#new_image").css("display","none");

$("#delete_image").click(function(){
if ($("#delete_image").is(":checked")){
$("#new_image").show(600);
} else {
$("#new_image").hide(600);
}
});
});

$(document).ready(function(){
$('.file').preimage();
});

</script>
<style>
#loading{
margin-left: auto;
margin-right: auto;
display:none;
}

.prev_container{
overflow: auto;
width: 300px;
height: 135px;
}

.prev_thumb{
margin: 10px;
height: 100px;
}
</style>
<div id="content" class="container_16 clearfix">
<div class="grid_12">
<div class="box">
<?php
if($_REQUEST['confirm'] == "Modify Ad" && empty($errors) === true){

$ad = $_POST['ad-id'];
$new_cat = $_POST['category'];
$new_sub_cat = $_POST['sub-category'];
$new_title = sanitize($_POST['title']);
$new_price = sanitize($_POST['price']);
$new_description = sanitize($_POST['description']);
$delete_image = $_POST['delete_image'];
$original = $_POST['old-image'];

if(!empty($delete_image)){
$max_size = 524288000;
$required_image_ext = array('jpg', 'jpeg', 'gif', 'png');

$file_name = $_FILES["file"]["name"];
$file_ext = (explode(".", $file_name));
$file_ext = strtolower(end($file_ext));
$file_size = $_FILES["file"]["size"];
$file_tmp = $_FILES["file"]["tmp_name"];

$path_and_name = "../db_images/ad_images/".$file_name;
$new_name = time()."-".date("m-d-Y").".".$file_ext;
$new_path_name = "../db_images/ad_images/".$new_name;

if (in_array($file_ext, $required_image_ext) == false && (!empty($file_ext))) {
$errors[] = "<p>Improper format - Images must be in <strong>GIF</strong>, <strong>PNG</strong>, <strong>JPG</strong>, <strong>JPEG</strong> format.</p>";
}

if($file_size > $max_size){
$errors[] = "<p>The image file size is to large. It must be less than <strong>500mb</strong></p>";
}

file_delete($delete_image); [b][size=5][color=#FF0000]<------------ HERE[/color][/size][/b]

$move_result = move_uploaded_file($file_tmp, $path_and_name);
ak_img_resize($path_and_name, $new_path_name, 300, 250, $file_ext);

if(!$move_result){
$errors[] = "<p>There was an error uploading the image</p>";
}

}

if(!empty($new_name)){
mysql_query("UPDATE `ads` SET `cat_id` = '".$new_cat."', `sub_cat_id` = '".$new_sub_cat."', `title`='".$new_title."', `price`='".$new_price."', `description`='".$new_description."', WHERE `ad_id`='".$ad."'");
} else {
mysql_query("UPDATE `ads` SET `cat_id` = '".$new_cat."', `sub_cat_id` = '".$new_sub_cat."', `title`='".$new_title."', `price`='".$new_price."', `description`='".$new_description."', `image` = '".$new_name."' WHERE `ad_id`='".$ad."'");
}
echo"<h2>Your Ad has been Modified</h2>
<form id='select_form' action='/user/modify-ad.php' enctype='multipart/form-data' method='post'>
<p>
<label>New Category:</label>
<select id='category' name='category' >
<option value='-----'>-----</option>";
$sql_cat= mysql_query("SELECT `cat_id`, `c_name` FROM category");

while ($row = mysql_fetch_array($sql_cat)) {
if ($new_cat == $row['cat_id']) {
echo '<option value="' . $row['cat_id'] . '" selected="selected">' . $row['c_name'] . '</option>';
} else {
echo '<option value="' . $row['cat_id'] . '">' . $row['c_name'] . '</option>';
}
}
echo"</select>
</p>
<p>
<label>New Subcategory:</label>
<select name='sub-category' id='sub-category' >";
$sql_sub= mysql_query("SELECT `sub_id`, `sub_cat_name` FROM sub_category WHERE `cat_id` = '".$new_cat."'");
while ($row = mysql_fetch_array($sql_sub)) {
if ($new_sub_cat == $row['sub_id']) {
echo '<option value="' . $row['sub_id'] . '" selected="selected">' . $row['sub_cat_name'] . '</option>';
} else {
echo '<option value="' . $row['sub_id'] . '">' . $row['sub_cat_name'] . '</option>';
}
}
echo "</select>
</p>
<p>
<label>New Title</label>
<input type='text' name='title' id='title' value=".$new_title." \/>
</p>
<p>
<label>New Price</label>
<input type='text' name='price' id='price' value=".$new_price." \/>
</p>
<p>
<label>New Description</label>
<textarea name='description' id='description' >".$new_description."</textarea>
</p>";
if(empty($delete_image)){
echo"<p>
<label for ='image'>New Image</label>
<img src='/db_images/ad_images/".$original."' />
</p>";
} else {
echo "<p>
<label for ='image'>New Image</label>
<img src='/db_images/ad_images/".$new_name."' />
</p>";
}
echo "</form>";

} else if($_REQUEST['confirm'] == "Cancel" && empty($errors) === true){
header('Location: /user/edit.php');
exit();
} else {
$ad = mysql_query("SELECT * FROM `ads` WHERE `ad_id` = '".$_GET['ad']."'");
$row = mysql_fetch_assoc($ad);

//ad variables
$cat = $row['cat_id'];
$sub = $row['sub_cat_id'];
$title = stripslashes($row['title']);
$price = $row['price'];
$description = $row['description'];
$image = $row['image'];
?>
<h2>Modify your Ad</h2>
<form id="select_form" action="/user/modify-ad.php" enctype="multipart/form-data" method="post">
<input type='hidden' name='ad-id' id='ad-id' value="<?php echo $_GET['ad'] ?>" /><br />
<input type='hidden' name='old-image' id='old-image' value="<?php echo $image ?>" /><br />
<p>
<label>Change category:</label>
<select id="category" name="category" >
<option value="-----">-----</option>
<?php
$sql_cat= mysql_query("SELECT `cat_id`, `c_name` FROM category");

while ($row = mysql_fetch_array($sql_cat)) {
if ($cat == $row['cat_id']) {
echo '<option value="' . $row['cat_id'] . '" selected="selected">' . $row['c_name'] . '</option>';
} else {
echo '<option value="' . $row['cat_id'] . '">' . $row['c_name'] . '</option>';
}
}
?>
</select>
</p>
<p>
<label>Change Subcategory:</label>
<select name="sub-category" id="sub-category" >
<?php
$sql_sub= mysql_query("SELECT `sub_id`, `sub_cat_name` FROM sub_category WHERE `cat_id` = '".$cat."'");

while ($row = mysql_fetch_array($sql_sub)) {
if ($sub == $row['sub_id']) {
echo '<option value="' . $row['sub_id'] . '" selected="selected">' . $row['sub_cat_name'] . '</option>';
} else {
echo '<option value="' . $row['sub_id'] . '">' . $row['sub_cat_name'] . '</option>';
}
}
?>
</select>
<span id="loading"><img src="/user/images/ajax-loader1.gif" ></span>
</p>
<p>
<label>Title</label>
<input type="text" name="title" id="title" value="<?php echo $title; ?>" />
</p>
<p>
<label>Price</label>
<input type="text" name="price" id="price" value="<?php echo $price; ?>" />
</p>
<p>
<label>Description</label>
<textarea name="description" id="description" ><?php echo $description; ?></textarea>
</p>
<p>
<label for ="image">Image</label>
<img src="/db_images/ad_images/<?php echo $image ?>" />
<label for-"Delete Image">Delete Image</label><input name="delete_image" type="checkbox" id="delete_image" value="<? echo $image; ?> "/>
</p>
<p id="new_image">
<label for ="image">New Image</label>
<input class="file" name="file" id="file" type='file' /><div id="prev_file"></div>
</p>
<input type='submit' name='confirm' value='Modify Ad'>
<input type='submit' name='confirm' value='Cancel'>
</form>
<?php } ?>
</div>
</div>
</div>
<?php include('../admin/includes/footer.php'); ?>

[/code]

 

the test directory and the user directory(which is where the modify-ad.php is located) are both on the same level in my directory tree.

 

Any help on this matter would be appreciated. I am sure that it is something small that I am over looking

Edited by mdmartiny

if (in_array($file_ext, $required_image_ext) == false && (!empty($file_ext))) {

$errors[] = "<p>Improper format - Images must be in <strong>GIF</strong>, <strong>PNG</strong>, <strong>JPG</strong>, <strong>JPEG</strong> format.</p>";

}

 

if($file_size > $max_size){

$errors[] = "<p>The image file size is to large. It must be less than <strong>500mb</strong></p>";

}

 

file_delete($delete_image);

 

$move_result = move_uploaded_file($file_tmp, $path_and_name);

ak_img_resize($path_and_name, $new_path_name, 300, 250, $file_ext);

 

if(!$move_result){

$errors[] = "<p>There was an error uploading the image</p>";

}

 

The above snippet has where I am trying to use the code.

I am trying to access my images directory which is

 

/public_html/db_images/ad_images/

Edited by mdmartiny

When you call this in your code:

ftp_chdir($conn_id, "/path/to/directory");

 

What is the exact value for "/path/to/directory"?

 

Also, could you place a file in your public_html with this code, and post the result?

<?php echo __DIR__;

Try with adding the /home/a6512617 bit before /public_html..... Right now you're telling the FTP server to look at the root of the server's file system, and find the "public_html" folder there. Naturally enough, it fails since that's not where said folder is located. ;)

 

Or, even better, use __DIR__ instead of /public_html, as that'll allow the script to work regardless of what host and/or username you're using.

Edited by Christian F.

I am getting this error message now

 

Warning: ftp_chdir() [function.ftp-chdir]: Can't change directory to /home/a6512617/public_html/db_images/ad_images/: No such file or directory in /home/a6512617/public_html/user/modify-ad.php on line 106

 

The file is there and the folder structure is there.

Edited by mdmartiny

That is what I do not understand. I have a test folder on my server where I tryout things before I let them go live. That script works perfectly in there no issues. But when I put the script in this file. I get error messages. So could it be something with the folders?

 

Verify that the constructed path on the remote server is what you think it is, and that it maps to the actual path of the desired folder. I'm not sure what you're doing, since you haven't really given us any detailed information, but it sounds like you're messing about with the file locations when uploading the script. Or at the very least the development environment does not map directly to the production development, when it comes to file and directory locations.

If he's using a linux machine as home computer, I'm going to write him down a simple bash script that lists out all files in that particular directory.

 

EDIT: I'm pretty sure that that file doesn't exist or it contains different characters.

Edited by jazzman1

I have a test directory... this ias where I write scripts and test things out before I put it on the live server. When I was testing out the ftp_delete function. Everything worked. Deleted the files with no issues no errors or anything.

 

When I moved the actual script into the user file. This is when the trouble began and I started getting the errors. That I have posted above.

 

The files are in the appropriate directories and they are there. I have checked them every time I have tried deleting the files and they are still there.

 

What I am trying to figure out is. Why doesn't it work when the test folder and the user folder are on the same directory tree level. When I get home from work tonight I will take a snapshot of my directories and everything for a better description.

file_delete($original);

function file_delete($file){
$ftp_server = "xxxxxxx.xxxxx.xxx";
$ftp_user = "xxxxxxx";
$ftp_pass = "xxxxxxx";

$conn_id = ftp_connect($ftp_server) or die("Could not connect to".$ftp_server);

$login_result = ftp_login($conn_id, $ftp_user, $ftp_pass);

ftp_chdir($conn_id, "/public_html/db_images/ad_images");

ftp_delete($conn_id, $file);

ftp_close($conn_id);
}

I got it to work after some more tinkering around with it...

 

I was not changing directories because I was adding a slash at the end when there should of been none. I fixed the other error by placing the name of the file to be deleted into a different variable.

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.